[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2862) Collection is not associated with any session exception when doing an eager fetch on a non-unique collection.

Lorenzo Resta (JIRA) noreply at atlassian.com
Tue Oct 2 15:28:24 EDT 2007


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

Lorenzo Resta commented on HHH-2862:
------------------------------------

I am also having the same issue here. I tracked down that for some reason two collections had the same owner, resulting in creation of to persistent collections. The reason for that was corrupt data in our database, however after a debugging session i noticed that StatefulPersistenceContext only removes already existing collections from the List collectionEntries, but not from the List nonlazyCollections, which then leads to this exception during the call forceInitialization on the collection since the session was previously unset.

This is our mapping:

<hibernate-mapping>
    <class name="ch.deltaenergy.et3000.customermgmt.Customer" table="RET_CUSTOMER_V" schema="ET3000" 
    				lazy="false" optimistic-lock="version">
        <cache usage="nonstrict-read-write" include="all" region="Basicdata.read-write"/>           
        <id name="creationSeq" type="java.lang.Long" unsaved-value="-1">
            <column name="CREATION_SEQ" precision="22" scale="0" />
            <generator class="sequence">
               <param name="sequence">SEQ_UNIVERSAL</param>
            </generator>
        </id>		
        <version
        	column="hib_version"
        	name="hibVersion"
        	type="long" 
        	access="property"
        	generated="always"/>
        
        <property name="seqPk" type="java.lang.Long" generated="always" insert="false" update="false">
            <column name="SEQ_PK" precision="22" scale="0" />
        </property>
        <property name="validFrom" type="java.util.Date" generated="always" insert="false" update="false">
            <column name="VALID_FROM" length="7" />
        </property>
        <property name="validTo" type="java.util.Date" generated="always" insert="false" update="false">
            <column name="VALID_TO" length="7" />
        </property>

        <many-to-one name="status" not-null="false" 
             lazy="false" 
             entity-name="ch.deltaenergy.et3000.customermgmt.CustomerStatus" 
			 cascade="none"
             fetch="select"              
             column="STATUS_ID"/>
               
        <many-to-one name="mandator" not-null="false" 
             lazy="false" 
             entity-name="ch.deltaenergy.et3k.basicdata.Mandator" 
			 cascade="none"
             fetch="select"              
             column="MANDATOR_ID"/>        
             
        <property name="dateCreated" type="java.util.Date" generated="always" insert="false" update="false">
            <column name="DATE_CREATED" length="7" />
        </property>

        <many-to-one name="userCreated" not-null="false" 
             lazy="false" 
             entity-name="ch.deltaenergy.et3k.basicdata.User" 
			 cascade="none"
             fetch="select"              
             column="USER_CREATED_ID"/>
        
        <property name="functionCreated" type="java.lang.String">
            <column name="FUNCTION_CREATED" length="30" />
        </property>
        <property name="dateModified" type="java.util.Date" generated="always" insert="false" update="false">
            <column name="DATE_MODIFIED" length="7" />
        </property>

        <many-to-one name="userModified" not-null="false" 
             lazy="false" 
             entity-name="ch.deltaenergy.et3k.basicdata.User" 
			 cascade="none"
             fetch="select"              
             column="USER_MODIFIED_ID"/>
        
        <property name="functionModified" type="java.lang.String">
            <column name="FUNCTION_MODIFIED" length="30" />
        </property>
        <property name="customerNo" type="java.lang.String">
            <column name="CUSTOMER_NO" length="30" />
        </property>
        
        <many-to-one name="parentCustomer" not-null="false" 
             lazy="false" 
             entity-name="ch.deltaenergy.et3000.customermgmt.Customer" 
			 cascade="none"
             fetch="select"              
             column="PARENT_CUSTOMER_ID"/>         
        
        <property name="isCompany" type="yes_no">
            <column name="IS_COMPANY_YN" length="1" />
        </property>
        
        <many-to-one name="customerType" not-null="false" 
             lazy="false" 
             entity-name="ch.deltaenergy.et3000.customermgmt.CustomerType" 
			 cascade="none"
             fetch="select"              
             column="CUSTOMER_TYPE_ID"/>        
        
        <many-to-one name="language" not-null="false" 
             lazy="false" 
             entity-name="ch.deltaenergy.et3k.translation.Sprache" 
			 cascade="none"
             fetch="select"              
             column="ISO_LANGUAGE_CD"/>                  
                   
        <property name="companyName" type="java.lang.String">
            <column name="COMPANY_NAME" length="70" />
        </property>
        <property name="companyNameExt" type="java.lang.String">
            <column name="COMPANY_NAME_EXT" length="35" />
        </property>
        <property name="corporateStructure" type="java.lang.String">
            <column name="CORPORATE_STRUCTURE" length="20" />
        </property>
        <property name="holidayGroupId" type="java.lang.Long">
            <column name="HOLIDAY_GROUP_ID" precision="22" scale="0" />
        </property>
        
        <many-to-one name="kamUser" not-null="false" 
             lazy="false" 
             entity-name="ch.deltaenergy.et3k.basicdata.User" 
			 cascade="none"
             fetch="select"              
             column="KAM_USER_ID"/>        
             
		<many-to-one name="kamSubstUser" not-null="false" 
             lazy="false" 
             entity-name="ch.deltaenergy.et3k.basicdata.User" 
			 cascade="none"
             fetch="select"              
             column="KAM_SUBST_USER_ID"/>
        
        <property name="debitorNo" type="java.lang.String">
            <column name="DEBITOR_NO" length="35" />
        </property>
        <property name="creditorNo" type="java.lang.String">
            <column name="CREDITOR_NO" length="35" />
        </property>
        <property name="description" type="java.lang.String">
            <column name="DESCRIPTION" length="80" />
        </property>
        <property name="paymentModeId" type="java.lang.Long">
            <column name="PAYMENT_MODE_ID" precision="22" scale="0" />
        </property>
        <property name="paymentConditionId" type="java.lang.Long">
            <column name="PAYMENT_CONDITION_ID" precision="22" scale="0" />
        </property>
        <property name="displayAs" type="java.lang.String">
            <column name="DISPLAY_AS" length="80" />
        </property>        
	

        <bag name="addresses" cascade="all" 
             where="LINK_TYPE = 'RET_CUSTOMER_KEY'" lazy="false" optimistic-lock="true" >
			<key column="LINK_ID"  property-ref="seqPk" not-null="true"/>
			<one-to-many class="ch.deltaenergy.et3000.customermgmt.Address" />
		</bag>
    </class>
</hibernate-mapping>

note that the collection causing the problem, is the addresses collection, For some weird reason we had two customer objects with the same property "seqPK".

> Collection is not associated with any session exception when doing an eager fetch on a non-unique collection.
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-2862
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2862
>             Project: Hibernate3
>          Issue Type: Bug
>         Environment: Hibernate 3.1.3 - Hibernate 3.2.5, HSQLDB, Java5
>            Reporter: Paul Andrews
>
> It is basically caused by having an eager collection where the key of the collection is not unique in the results.
> The code works as follows in CollectionType.getCollection():
>                                 ....
> 				persistenceContext.addUninitializedCollection( persister, collection, key );
> 	
> 				// some collections are not lazy:
> 				if ( initializeImmediately( entityMode ) ) {
> 					session.initializeCollection( collection, false );
> 				}
> 				else if ( !persister.isLazy() ) {
> 					persistenceContext.addNonLazyCollection( collection );
> 				}
> 	
> 				if ( hasHolder( entityMode ) ) {
> 					session.getPersistenceContext().addCollectionHolder( collection );
> 				}
> if persistenceContext.addUninitializedCollection() detects that the collection with the given key has already been added it clears the session on the old instance of the collection (sets it to null). However, that collection has already been added to the persistence context by an earlier call to this method. So later when StatefulPersistenceContext.initializeNonLazyCollections() is called it iterates through all of the collections in the persistence context (including those which have had their session set to null by addUninitializedCollection()), calling forceInitialization() which throws a 'collection is not associated with any session' exception.

-- 
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