Mark, thanks for the patch - but would you please submit this to the
patch manager? I havn't been able to find time to review this, and I
don't want it to get lost in the list....

sorry about that..

TIA

Gavin




                                                                                       
                                               
                    Mark Woon                                                          
                                               
                    <[EMAIL PROTECTED]>         To:     Hibernate Mailing List <[EMAIL 
PROTECTED]>    
                    Sent by:                                cc:                        
                                               
                    [EMAIL PROTECTED]       Subject:     [Hibernate] New appreach for 
alias names                     
                    eforge.net                                                         
                                               
                                                                                       
                                               
                                                                                       
                                               
                    22/01/03 01:10 AM                                                  
                                               
                                                                                       
                                               
                                                                                       
                                               





I've come up with another approach to resolve the problem with Hibernate
generating column aliases that are too long.  Instead of appending a
suffix to the original name, I've modified it so that it generates
unique names.  The change to handle this was simple enough (in
EntityPersister and MultiTableEntityPersister), but it took a long time
to figure out why loading joined-subclasses didn't work too well.  That
required the change to Loader.

In any case, I hope this patch works out better than the last one.
 Gavin, I really need a solution to this problem since this is my only
remaining problem with Hibernate.

-Mark

Index: cirrus/hibernate/loader/Loader.java
===================================================================
RCS file:
/cvsroot/hibernate/Hibernate/cirrus/hibernate/loader/Loader.java,v
retrieving revision 1.34
diff -c -b -r1.34 Loader.java
*** cirrus/hibernate/loader/Loader.java        15 Jan 2003 12:52:40 -0000
      1.34
--- cirrus/hibernate/loader/Loader.java        21 Jan 2003 13:35:14 -0000
***************
*** 164,170 ****

                                                              // grab its
state from the ResultSet and keep it in the Session
                                                              // (but don't
yet initialize the object itself)
!
loadFromResultSet( rs, row[i], keys[i].getIdentifier(), suffixes[i],
session );

                                                              if
(twoPhaseLoad) {

//materialize associations (and initialize the object) later
--- 164,170 ----

                                                              // grab its
state from the ResultSet and keep it in the Session
                                                              // (but don't
yet initialize the object itself)
!
loadFromResultSet( rs, persisters[i], row[i], keys[i].getIdentifier(),
suffixes[i], session );

                                                              if
(twoPhaseLoad) {

//materialize associations (and initialize the object) later
***************
*** 316,331 ****

           }

-
           /**
            * Hydrate an object from the SQL <tt>ResultSet</tt>
            */
!          private void loadFromResultSet(ResultSet rs, Object object,
Serializable id, String suffix, SessionImplementor session) throws
SQLException, HibernateException {

                     if ( log.isTraceEnabled() ) log.trace("Initializing
object from ResultSet: " + id);

                     // Get the persister for the _subclass_
!                    Loadable persister = (Loadable)
session.getPersister(object);

                     Object[] values = hydrate(rs, id, object, persister,
session, suffix);
                     session.postHydrate(persister, id, values, object,
getLockMode() );
--- 316,332 ----

           }

    /**
     * Hydrate an object from the SQL <tt>ResultSet</tt>
     */
!   private void loadFromResultSet(ResultSet rs, Loadable persister, Object
object, Serializable id, String suffix, SessionImplementor session)
!     throws SQLException, HibernateException {

      if ( log.isTraceEnabled() ) log.trace("Initializing object from
ResultSet: " + id);

      // Get the persister for the _subclass_
!     // Why?  In any case, can't do this with new column aliases
!     //Loadable persister = (Loadable) session.getPersister(object);

      Object[] values = hydrate(rs, id, object, persister, session,
suffix);
      session.postHydrate(persister, id, values, object, getLockMode() );
Index: cirrus/hibernate/persister/EntityPersister.java
===================================================================
RCS file:
/cvsroot/hibernate/Hibernate/cirrus/hibernate/persister/EntityPersister.java,v

retrieving revision 1.49
diff -c -b -r1.49 EntityPersister.java
*** cirrus/hibernate/persister/EntityPersister.java           17 Jan 2003
10:27:10 -0000       1.49
--- cirrus/hibernate/persister/EntityPersister.java           21 Jan 2003
13:35:15 -0000
***************
*** 63,73 ****
--- 63,75 ----
           private transient final int[] propertyColumnSpans;
           private transient final boolean[] definedOnSubclass;
    private transient final String[][] propertyColumnNames;
+   private transient final String[][] propertyColumnNameAliases;
           private transient final String[][]
subclassPropertyColumnNameClosure;

           private transient final String discriminatorColumnName;
           private transient final String[] columnNames;
           private transient final String[] subclassColumnClosure;
+   private transient final String[] subclassColumnClosureAliases;
           private transient final Type[] subclassPropertyTypeClosure;
           private transient final Class[] subclassClosure;
           private transient final boolean hasColumns;
***************
*** 178,184 ****
           }

           public String[] getPropertyColumnNames(int i) {
!                    return propertyColumnNames[i];
           }

           public DiscriminatorType getDiscriminatorType() {
--- 180,186 ----
           }

           public String[] getPropertyColumnNames(int i) {
!                    return propertyColumnNameAliases[i];
           }

           public DiscriminatorType getDiscriminatorType() {
***************
*** 678,683 ****
--- 680,686 ----
                     // PROPERTIES

                     propertyColumnNames = new String[hydrateSpan][];
+     propertyColumnNameAliases = new String[hydrateSpan][];
                     propertyColumnSpans = new int[hydrateSpan];
                     ArrayList columns = new ArrayList();
                     HashSet thisClassProperties = new HashSet();
***************
*** 691,704 ****
                               thisClassProperties.add(prop);

                               String[] colNames = new String[
propertyColumnSpans[i] ];
                               Iterator colIter = prop.getColumnIterator();
                               int j=0;
                               while ( colIter.hasNext() ) {
                                          String colname = ( (Column)
colIter.next() ).getName();
!                                         colNames[j++] = colname;
                                          columns.add(colname);
                               }
                               propertyColumnNames[i] = colNames;

                               initPropertyPaths(prop, "");
                               i++;
--- 694,711 ----
                               thisClassProperties.add(prop);

                               String[] colNames = new String[
propertyColumnSpans[i] ];
+       String[] colAliases = new String[ propertyColumnSpans[i] ];
                               Iterator colIter = prop.getColumnIterator();
                               int j=0;
                               while ( colIter.hasNext() ) {
                                          String colname = ( (Column)
colIter.next() ).getName();
!                                         colNames[j] = colname;
!         colAliases[j] = "x" + i + '_' + j + '_';
                                          columns.add(colname);
+         j++;
                               }
                               propertyColumnNames[i] = colNames;
+       propertyColumnNameAliases[i] = colAliases;

                               initPropertyPaths(prop, "");
                               i++;
***************
*** 713,722 ****
--- 720,731 ----

                     columns.clear();
                     ArrayList types = new ArrayList();
+     ArrayList aliases = new ArrayList();
                     ArrayList propColumns = new ArrayList();
                     ArrayList joinedFetchesList = new ArrayList();
                     ArrayList definedBySubclass = new ArrayList();

+     i = 0;
                     iter = model.getSubclassPropertyClosureIterator();
                     while ( iter.hasNext() ) {
                               Property prop = (Property) iter.next();
***************
*** 728,741 ****
                               while ( colIter.hasNext() ) {
                                          Column col = (Column)
colIter.next();
                                          columns.add( col.getName() );
!                                         cols[l++]=col.getName();
                               }
                               propColumns.add(cols);
                               joinedFetchesList.add( new Integer(
                                          prop.getValue().enableJoinedFetch
()
                               ) );
                     }
                     subclassColumnClosure = (String[])
columns.toArray(STRING_ARRAY);
                     subclassPropertyTypeClosure = (Type[])
types.toArray(TYPE_ARRAY);
                     subclassPropertyColumnNameClosure = (String[][])
propColumns.toArray( new String[ propColumns.size() ][] );

--- 737,754 ----
                               while ( colIter.hasNext() ) {
                                          Column col = (Column)
colIter.next();
                                          columns.add( col.getName() );
!                                         cols[l]=col.getName();
!         aliases.add("x" + i + '_' + l + '_');
!         l++;
                               }
                               propColumns.add(cols);
                               joinedFetchesList.add( new Integer(
                                          prop.getValue().enableJoinedFetch
()
                               ) );
+       i++;
                     }
                     subclassColumnClosure = (String[])
columns.toArray(STRING_ARRAY);
+     subclassColumnClosureAliases = (String[])
aliases.toArray(STRING_ARRAY);
                     subclassPropertyTypeClosure = (Type[])
types.toArray(TYPE_ARRAY);
                     subclassPropertyColumnNameClosure = (String[][])
propColumns.toArray( new String[ propColumns.size() ][] );

***************
*** 911,917 ****
                                          .append('.')
                                          .append( cols[i] )
                                          .append(" as ")
!                                         .append(
StringHelper.suffix(cols[i], suffix) );
                     }
                     return buf.toString();
           }
--- 924,930 ----
                                          .append('.')
                                          .append( cols[i] )
                                          .append(" as ")
!                                         .append(
StringHelper.suffix(subclassColumnClosureAliases[i], suffix) );
                     }
                     return buf.toString();
           }
Index: cirrus/hibernate/persister/MultiTableEntityPersister.java
===================================================================
RCS file:
/cvsroot/hibernate/Hibernate/cirrus/hibernate/persister/MultiTableEntityPersister.java,v

retrieving revision 1.47
diff -c -b -r1.47 MultiTableEntityPersister.java
*** cirrus/hibernate/persister/MultiTableEntityPersister.java           17
Jan 2003 10:27:10 -0000        1.47
--- cirrus/hibernate/persister/MultiTableEntityPersister.java           21
Jan 2003 13:35:16 -0000
***************
*** 776,782 ****
                     propertyColumnSpans = new int[hydrateSpan];

                     HashSet thisClassProperties = new HashSet();
-
                     Iterator iter = model.getPropertyClosureIterator();
                     int i=0;

--- 776,781 ----
***************
*** 796,802 ****
                                          Column col = (Column)
colIter.next();
                                          String colname = col.getName();
                                          propCols[j] = colname;
!                                         propAliases[j] = col.getName() +
tab.getUniqueInteger() + '_';
                                          j++;
                               }
                               propertyColumnNames[i] = propCols;
--- 795,801 ----
                                          Column col = (Column)
colIter.next();
                                          String colname = col.getName();
                                          propCols[j] = colname;
!                                         propAliases[j] = "x" +
tab.getUniqueInteger() + '_' + i + '_' + j + '_';
                                          j++;
                               }
                               propertyColumnNames[i] = propCols;
***************
*** 819,824 ****
--- 818,824 ----
                     ArrayList propTables = new ArrayList();
                     ArrayList definedBySubclass = new ArrayList();

+     i = 0;
                     iter = model.getSubclassPropertyClosureIterator();
                     while ( iter.hasNext() ) {
                               Property prop = (Property) iter.next();
***************
*** 835,854 ****
                                          Column col = (Column)
colIter.next();
                                          columns.add( col.getName() );
                                          coltables.add(tabnum);
!                                         cols[l++]=col.getName();
!                                         aliases.add( col.getName() +
tab.getUniqueInteger() + '_' );
                               }
                               propColumns.add(cols);
                               joinedFetchesList.add( new Integer(
                                          prop.getValue().enableJoinedFetch
()
                               ) );
                     }
                     subclassColumnClosure = (String[])
columns.toArray(STRING_ARRAY);
                     subclassColumnClosureAliases = (String[])
aliases.toArray(STRING_ARRAY);
                     subclassColumnTableNumberClosure =
ArrayHelper.toIntArray(coltables);
                     subclassPropertyTypeClosure = (Type[])
types.toArray(TYPE_ARRAY);
                     subclassPropertyTableNumberClosure =
ArrayHelper.toIntArray(propTables);
-
                     subclassPropertyColumnNameClosure = (String[][])
propColumns.toArray( new String[ propColumns.size() ][] );

                     joinedFetch = new int[ joinedFetchesList.size() ];
--- 835,855 ----
                                          Column col = (Column)
colIter.next();
                                          columns.add( col.getName() );
                                          coltables.add(tabnum);
!                                         cols[l]=col.getName();
!         aliases.add( "x" + tab.getUniqueInteger() + '_' + i + '_' + l + '
_' );
!         l++;
                               }
                               propColumns.add(cols);
                               joinedFetchesList.add( new Integer(
                                          prop.getValue().enableJoinedFetch
()
                               ) );
+       i++;
                     }
                     subclassColumnClosure = (String[])
columns.toArray(STRING_ARRAY);
                     subclassColumnClosureAliases = (String[])
aliases.toArray(STRING_ARRAY);
                     subclassColumnTableNumberClosure =
ArrayHelper.toIntArray(coltables);
                     subclassPropertyTypeClosure = (Type[])
types.toArray(TYPE_ARRAY);
                     subclassPropertyTableNumberClosure =
ArrayHelper.toIntArray(propTables);
                     subclassPropertyColumnNameClosure = (String[][])
propColumns.toArray( new String[ propColumns.size() ][] );

                     joinedFetch = new int[ joinedFetchesList.size() ];




**********************************************************************
Any personal or sensitive information contained in this email and
attachments must be handled in accordance with the Victorian Information
Privacy Act 2000, the Health Records Act 2001 or the Privacy Act 1988
(Commonwealth), as applicable.

This email, including all attachments, is confidential.  If you are not the
intended recipient, you must not disclose, distribute, copy or use the
information contained in this email or attachments.  Any confidentiality or
privilege is not waived or lost because this email has been sent to you in
error.  If you have received it in error, please let us know by reply
email, delete it from your system and destroy any copies.
**********************************************************************





-------------------------------------------------------
This SF.net email is sponsored by: Scholarships for Techies!
Can't afford IT training? All 2003 ictp students receive scholarships.
Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
www.ictp.com/training/sourceforge.asp
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to