-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Bug in subclass mapping using joins with fetch="select&
PostPosted: Wed Nov 26, 2008 2:38 pm 
Newbie

Joined: Wed Nov 26, 2008 12:00 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.3.1-GA

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.cisco.nm.mappings.other">
<class name="Master" table="M5_MASTER">

<id name="id" column="ID" type="long">
<generator class="sequence" />
</id>

<list name="ttmulti" cascade="save-update,delete">
<key column="M5_TTMULTI_ID" not-null="true"/>
<list-index column="M5_TTMULTI_POS" />
<one-to-many class="com.cisco.nm.mappings.wideNdeep.TreeTop" not-found="ignore" />
</list>

</class>

</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.cisco.nm.mappings.wideNdeep">
<class name="TreeTop" table="M5_TREETOP" discriminator-value="TT">

<id name="id" column="ID" type="long">
<generator class="sequence" />
</id>

<discriminator column="TT_DISC" type="string" />

<property name="name" column="NAME" />
<property name="ttboolvar" column="ttboolvar" />

<many-to-one name="myMaster"
class="com.cisco.nm.mappings.other.Master"
column="M5_TTMULTI_ID"
cascade="save-update,delete"
not-null="true"
insert="false"
update="false"
foreign-key="M5_" />

</class>

</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.cisco.nm.mappings.wideNdeep">
<subclass name="Level1Leaf1" discriminator-value="L1L1" extends="TreeTop">
<join fetch="select" table="M5_L1L1">
<key column="M5_L1L1_JID"/>

<property name="l1l1boolvar" column="l1l1boolvar" />

</join>
</subclass>

</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.cisco.nm.mappings.wideNdeep">
<subclass name="Level2Leaf11" discriminator-value="L2L11" extends="Level1Leaf1">
<join fetch="select" table="M5_L2L11">
<key column="M5_L2L11_JID" />

<property name="l2l11boolvar" column="l2l11boolvar" />
<property name="l2l11floatvar" column="l2l11floatvar" />
<property name="l2l11intvar" column="l2l11intvar" />
</join>
</subclass>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
   Session s = sf.openSession();
   Transaction tx = null;
   tx = s.beginTransaction();
   Master m = new Master();
   List<TreeTop> ttl = new LinkedList<TreeTop>();
   Level2Leaf11 tti = new Level2Leaf11();
   tti.setName("TreeTop");
   tti.setTtboolvar(true);
   tti.setL1l1boolvar(false);
   tti.setL2l11boolvar(true);
   tti.setL2l11floatvar(7.78f);
   tti.setL2l11intvar(333);         
   tti.setMyMaster(m);
   ttl.add(tti);
   m.setTtmulti(ttl);
   long m_id = (Long)s.save(m);
   tx.commit();
   s.close();

   s = sf.openSession();
   Master nm = (Master)s.get(Master.class, m_id);   
   int lm = nm.getTtmulti().size();
   System.out.println("Print the result ("+lm+")");
   System.out.println(nm);
   s.close();


Full stack trace of any exception that occurs:
Quote:
18:27:44,166 DEBUG JDBCExceptionReporter:92 - could not initialize a collection: [com.cisco.nm.mappings.other.Master.ttmulti#1] [select ttmulti0_.M5_TTMULTI_ID as M5_1_, ttmulti0_.ID as ID1_, ttmulti0_.M5_TTMULTI_POS as M6_1_, ttmulti0_.ID as ID1_0_, ttmulti0_.NAME as NAME1_0_, ttmulti0_.ttboolvar as ttboolvar1_0_, ttmulti0_.M5_TTMULTI_ID as M5_1_0_, ttmulti0_.TT_DISC as TT2_1_0_ from M5_TREETOP ttmulti0_ where ttmulti0_.M5_TTMULTI_ID=?]
java.sql.SQLException: Invalid column name
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:6221)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1557)
at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1528)
at org.hibernate.type.IntegerType.get(IntegerType.java:51)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:105)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2124)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1332)
at org.hibernate.loader.Loader.getRow(Loader.java:1230)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
at org.hibernate.loader.Loader.doQuery(Loader.java:724)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1743)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:131)
at org.hibernate.collection.PersistentList.size(PersistentList.java:114)
at RunTrialsForBug.main(RunTrialsForBug.java:192)
18:27:44,166 WARN JDBCExceptionReporter:100 - SQL Error: 17006, SQLState: null
18:27:44,166 ERROR JDBCExceptionReporter:101 - Invalid column name
org.hibernate.exception.GenericJDBCException: could not initialize a collection: [com.cisco.nm.mappings.other.Master.ttmulti#1]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2022)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1743)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:131)
at org.hibernate.collection.PersistentList.size(PersistentList.java:114)
at RunTrialsForBug.main(RunTrialsForBug.java:192)
Caused by: java.sql.SQLException: Invalid column name
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:6221)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1557)
at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1528)
at org.hibernate.type.IntegerType.get(IntegerType.java:51)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:105)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2124)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1332)
at org.hibernate.loader.Loader.getRow(Loader.java:1230)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
at org.hibernate.loader.Loader.doQuery(Loader.java:724)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
... 9 more


Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):
Hibernate: select treetop_1_.l1l1boolvar as l2_2_, treetop_2_.l2l11boolvar as l2_3_, treetop_2_.l2l11floatvar as l3_3_ from M5_L1L1 treetop_1_ inner join M5_L2L11 treetop_2_ on treetop_1_.M5_L1L1_JID=treetop_2_.M5_L2L11_JID where treetop_1_.M5_L1L1_JID=?

Debug level Hibernate log excerpt:
Quote:
18:27:43,432 DEBUG SQL:111 - select ttmulti0_.M5_TTMULTI_ID as M5_1_, ttmulti0_.ID as ID1_, ttmulti0_.M5_TTMULTI_POS as M6_1_, ttmulti0_.ID as ID1_0_, ttmulti0_.NAME as NAME1_0_, ttmulti0_.ttboolvar as ttboolvar1_0_, ttmulti0_.M5_TTMULTI_ID as M5_1_0_, ttmulti0_.TT_DISC as TT2_1_0_ from M5_TREETOP ttmulti0_ where ttmulti0_.M5_TTMULTI_ID=?
Hibernate: select ttmulti0_.M5_TTMULTI_ID as M5_1_, ttmulti0_.ID as ID1_, ttmulti0_.M5_TTMULTI_POS as M6_1_, ttmulti0_.ID as ID1_0_, ttmulti0_.NAME as NAME1_0_, ttmulti0_.ttboolvar as ttboolvar1_0_, ttmulti0_.M5_TTMULTI_ID as M5_1_0_, ttmulti0_.TT_DISC as TT2_1_0_ from M5_TREETOP ttmulti0_ where ttmulti0_.M5_TTMULTI_ID=?
18:27:43,432 TRACE AbstractBatcher:513 - preparing statement
18:27:43,697 DEBUG AbstractBatcher:426 - about to open ResultSet (open ResultSets: 0, globally: 0)
18:27:43,697 DEBUG Loader:1078 - result set contains (possibly empty) collection: [com.cisco.nm.mappings.other.Master.ttmulti#1]
18:27:43,697 TRACE LoadContexts:191 - constructing collection load context for result set [oracle.jdbc.driver.OracleResultSetImpl@12bcd4b]
18:27:43,697 TRACE CollectionLoadContext:113 - starting attempt to find loading collection [[com.cisco.nm.mappings.other.Master.ttmulti#1]]
18:27:43,697 TRACE CollectionLoadContext:126 - collection not yet initialized; initializing
18:27:43,697 TRACE Loader:717 - processing result set
18:27:43,697 DEBUG Loader:722 - result set row: 0
18:27:43,713 DEBUG Loader:1197 - result row: EntityKey[com.cisco.nm.mappings.wideNdeep.TreeTop#2]
18:27:43,713 TRACE Loader:1379 - Initializing object from ResultSet: [com.cisco.nm.mappings.wideNdeep.Level2Leaf11#2]
18:27:43,713 TRACE AbstractEntityPersister:2059 - Hydrating entity: [com.cisco.nm.mappings.wideNdeep.Level2Leaf11#2]
18:27:43,713 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 1, globally: 1)
18:27:43,713 DEBUG SQL:111 - select treetop_1_.l1l1boolvar as l2_2_, treetop_2_.l2l11boolvar as l2_3_, treetop_2_.l2l11floatvar as l3_3_ from M5_L1L1 treetop_1_ inner join M5_L2L11 treetop_2_ on treetop_1_.M5_L1L1_JID=treetop_2_.M5_L2L11_JID where treetop_1_.M5_L1L1_JID=?
Hibernate: select treetop_1_.l1l1boolvar as l2_2_, treetop_2_.l2l11boolvar as l2_3_, treetop_2_.l2l11floatvar as l3_3_ from M5_L1L1 treetop_1_ inner join M5_L2L11 treetop_2_ on treetop_1_.M5_L1L1_JID=treetop_2_.M5_L2L11_JID where treetop_1_.M5_L1L1_JID=?
18:27:43,713 TRACE AbstractBatcher:513 - preparing statement
18:27:43,947 INFO IntegerType:203 - could not read column value from result set: l4_3_; Invalid column name
18:27:43,947 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 2, globally: 2)
18:27:43,947 TRACE AbstractBatcher:562 - closing statement
18:27:44,057 DEBUG AbstractBatcher:433 - about to close ResultSet (open ResultSets: 1, globally: 1)
18:27:44,119 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
18:27:44,119 TRACE AbstractBatcher:562 - closing statement


Suggested fix:
In AbstractEntityPersister.createSelect(...);
Replace...
Code:
for ( int i = 0; i < subclassColumnNumbers.length; i++ ) {
[b]
   if ( subclassColumnSelectableClosure[i] ) {
   int columnNumber = subclassColumnNumbers[i];
[/b]
   final String subalias = generateTableAlias( getRootAlias(), columnTableNumbers[columnNumber] );
   selectFragment.addColumn( subalias, columns[columnNumber], columnAliases[columnNumber] );
   }
}


with

Code:
for ( int i = 0; i < subclassColumnNumbers.length; i++ ) {
[b]
   int columnNumber = subclassColumnNumbers[i];
   if ( subclassColumnSelectableClosure[columnNumber ] ) {
[/b]
   final String subalias = generateTableAlias( getRootAlias(), columnTableNumbers[columnNumber] );
   selectFragment.addColumn( subalias, columns[columnNumber], columnAliases[columnNumber] );
   }
}


This cures the problem in all cases I've looked at.

Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html
Quote:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2008 4:58 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
http://opensource.atlassian.com/project ... e/HHH-3636

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.