From: Jakub M. (JIRA) <no...@at...> - 2006-06-07 17:28:22
|
Lazy loading problem when property-ref is used for collections -------------------------------------------------------------- Key: HHH-1820 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1820 Project: Hibernate3 Type: Bug Versions: 3.1.3 Environment: Oracle 8.1.7 Reporter: Jakub Mendys Consider mapping <class name="MedDRATerm" table="MBROW_MEDDRA_TERMS" mutable="false" batch-size="50"> <cache usage="read-only" region="dictionary" /> <id name="medDRATermId" type="long" column="TERM_ID"> <generator class="assigned" /> </id> <map name="termNames" table="MBROW_TERM_NAMES" lazy="true" batch-size="50"> <cache usage="read-only" region="dictionary" /> <key column="MEDDRA_CODE" property-ref="medDRACode" /> <index column="LANGUAGE_ID" type="com.roche.dss.meddra.dao.type.LanguageType" /> <element column="NAME" type="string" /> </map> <property name="medDRACode" column="MEDDRA_CODE" type="com.roche.dss.meddra.dao.type.MedDRACodeType" /> </class> <class name="MedDRATermInstance" table="MBROW_MEDDRA_TREES" mutable="false"> <cache usage="read-only" region="dictionary" /> <id name="medDRATermInstanceId" type="long" column="NODE_ID"> <generator class="assigned" /> </id> <many-to-one name="medDRATerm" class="MedDRATerm" column="TERM_ID" fetch="join" not-null="true" insert="false" update="false" /> </class> When you execute a query: from MedDRATermInstance i where i.version=:versionId and i.medDRATerm in (:terms) and then using the _same session_ you will iterate over returned collection and will call session.get(id) for returned records it is very likely that for _SOME_ (random??) of objects when you will try to access its properties you will get following exception thrown: 2006-06-07 19:25:11,942 ERROR org.hibernate.LazyInitializationException - failed to lazily initialize a collection of role: com.roche.dss.meddra.model.MedDRATerm.termNames, no session or session was losed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.roche.dss.meddra.model.MedDRATerm.termNames, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.readElementByIndex(AbstractPersistentCollection.java:151) at org.hibernate.collection.PersistentMap.get(PersistentMap.java:127) Calling session.clear() before session.get() helps to workaround this but causes all the records to be fethed again from the database. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
From: Jakub M. (JIRA) <no...@at...> - 2006-06-07 18:00:42
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1820?page=comments#action_23294 ] Jakub Mendys commented on HHH-1820: ----------------------------------- Examle code to reproduce problem: String SQL = "select inst from MedDRATermInstance inst " + " where inst.version = :version and inst.medDRATerm.medDRACode in (:codes) "; Query query = session.createQuery( SQL ); query.setCacheable( true ); query.setInteger( "version", version.getMedDRAVersionId() ); query.setParameterList( "codes", medDRACodes ); List result = query.list(); for (Iterator iter = result.iterator(); iter.hasNext();) { MedDRATermInstance term1 = (MedDRATermInstance) iter.next(); MedDRATermInstance term2 = (MedDRATermInstance) session.get( MedDRATermInstance.class, new Long( term1 .getMedDRATermInstanceId() ) ); assertNotNull( term2.getMedDRATerm().getTermName( Language.DEFAULT ) ); } > Lazy loading problem when property-ref is used for collections > -------------------------------------------------------------- > > Key: HHH-1820 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1820 > Project: Hibernate3 > Type: Bug > Versions: 3.1.3 > Environment: Oracle 8.1.7 > Reporter: Jakub Mendys > > > Consider mapping > <class name="MedDRATerm" table="MBROW_MEDDRA_TERMS" mutable="false" > batch-size="50"> > <cache usage="read-only" region="dictionary" /> > <id name="medDRATermId" type="long" column="TERM_ID"> > <generator class="assigned" /> > </id> > <map name="termNames" table="MBROW_TERM_NAMES" lazy="true" > batch-size="50"> > <cache usage="read-only" region="dictionary" /> > <key column="MEDDRA_CODE" property-ref="medDRACode" /> > <index column="LANGUAGE_ID" > type="com.roche.dss.meddra.dao.type.LanguageType" /> > <element column="NAME" type="string" /> > </map> > <property name="medDRACode" column="MEDDRA_CODE" > type="com.roche.dss.meddra.dao.type.MedDRACodeType" /> > </class> > <class name="MedDRATermInstance" table="MBROW_MEDDRA_TREES" > mutable="false"> > <cache usage="read-only" region="dictionary" /> > <id name="medDRATermInstanceId" type="long" column="NODE_ID"> > <generator class="assigned" /> > </id> > <many-to-one name="medDRATerm" class="MedDRATerm" > column="TERM_ID" fetch="join" not-null="true" insert="false" > update="false" /> > </class> > When you execute a query: > from MedDRATermInstance i where i.version=:versionId and i.medDRATerm in (:terms) > and then using the _same session_ you will iterate over returned collection and will call session.get(id) for returned records it is very likely that for _SOME_ (random??) of objects when you will try to access its properties you will get following exception thrown: > 2006-06-07 19:25:11,942 ERROR org.hibernate.LazyInitializationException - failed to lazily initialize a collection of role: com.roche.dss.meddra.model.MedDRATerm.termNames, no session or session was > losed > org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.roche.dss.meddra.model.MedDRATerm.termNames, no session or session was closed > at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) > at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) > at org.hibernate.collection.AbstractPersistentCollection.readElementByIndex(AbstractPersistentCollection.java:151) > at org.hibernate.collection.PersistentMap.get(PersistentMap.java:127) > Calling session.clear() before session.get() helps to workaround this but causes all the records to be fethed again from the database. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
From: Ben H. (JIRA) <no...@at...> - 2006-06-16 16:14:33
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1820?page=comments#action_23349 ] Ben Hall commented on HHH-1820: ------------------------------- We've encountered this problem in our web application while using DB2 for z/OS 7.0. However, we haven't seen this problem running against HSQLDB, either while running unit tests or in our application. > Lazy loading problem when property-ref is used for collections > -------------------------------------------------------------- > > Key: HHH-1820 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1820 > Project: Hibernate3 > Type: Bug > Versions: 3.1.3 > Environment: Oracle 8.1.7 > Reporter: Jakub Mendys > > > Consider mapping > <class name="MedDRATerm" table="MBROW_MEDDRA_TERMS" mutable="false" > batch-size="50"> > <cache usage="read-only" region="dictionary" /> > <id name="medDRATermId" type="long" column="TERM_ID"> > <generator class="assigned" /> > </id> > <map name="termNames" table="MBROW_TERM_NAMES" lazy="true" > batch-size="50"> > <cache usage="read-only" region="dictionary" /> > <key column="MEDDRA_CODE" property-ref="medDRACode" /> > <index column="LANGUAGE_ID" > type="com.roche.dss.meddra.dao.type.LanguageType" /> > <element column="NAME" type="string" /> > </map> > <property name="medDRACode" column="MEDDRA_CODE" > type="com.roche.dss.meddra.dao.type.MedDRACodeType" /> > </class> > <class name="MedDRATermInstance" table="MBROW_MEDDRA_TREES" > mutable="false"> > <cache usage="read-only" region="dictionary" /> > <id name="medDRATermInstanceId" type="long" column="NODE_ID"> > <generator class="assigned" /> > </id> > <many-to-one name="medDRATerm" class="MedDRATerm" > column="TERM_ID" fetch="join" not-null="true" insert="false" > update="false" /> > </class> > When you execute a query: > from MedDRATermInstance i where i.version=:versionId and i.medDRATerm in (:terms) > and then using the _same session_ you will iterate over returned collection and will call session.get(id) for returned records it is very likely that for _SOME_ (random??) of objects when you will try to access its properties you will get following exception thrown: > 2006-06-07 19:25:11,942 ERROR org.hibernate.LazyInitializationException - failed to lazily initialize a collection of role: com.roche.dss.meddra.model.MedDRATerm.termNames, no session or session was > losed > org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.roche.dss.meddra.model.MedDRATerm.termNames, no session or session was closed > at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) > at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) > at org.hibernate.collection.AbstractPersistentCollection.readElementByIndex(AbstractPersistentCollection.java:151) > at org.hibernate.collection.PersistentMap.get(PersistentMap.java:127) > Calling session.clear() before session.get() helps to workaround this but causes all the records to be fethed again from the database. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |