[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1820) Lazy loading problem when property-ref is used for collections

srs (JIRA) noreply at atlassian.com
Tue Dec 4 14:14:56 EST 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1820?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29049 ] 

srs commented on HHH-1820:
--------------------------

I can confirm that we get the same LazyInitializationException on many-to-many relations with propery-ref's when using lazy loading on MySQL 5.x and Hibernate 3.1.2.

> 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
>          Issue Type: Bug
>    Affects 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

        



More information about the hibernate-issues mailing list