Hey guys
I am getting the infamous error could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed When trying to update the persistent state of a detached instance .
So here's what i do
1. Open session 1 query for an object in my case look for a HumanImpl
which is a subclass of PartyImpl ( check the mappings )
2. So i get a single object and close the session 1
3. I do changes to this object changed something in it
4. Now i want to update this object i basically invoke this command.
open session 2 and
session.saveOrUpdateCopy( object );
5. Now this throws a Lazy initialization Exception when it start to work with at ObjectAssociationImpl#8a818b970805c715010805fc9a750005
( check the trace ).
What am i doing wrong
Depth of that object
PartyImpl
|
|-------- HumanImpl
|---------------|
|-------------- |--- List of addresses
|
|--------Set of Object Associations
Thank you
Hibernate version:3.0.5
Mapping documents: Party.hbm.xml <class name="PartyImpl" polymorphism="implicit" proxy="PartyImpl" table="party"> <id column="party_id" name="partyID" type="string" unsaved-value="null"> <generator class="uuid.hex"/> </id> <discriminator column="discriminator_type" type="string"/> <many-to-one class="ObjectTypeImpl" column="object_type_id" insert="true" name="objectType" update="true"/> <property column="note" insert="true" name="note" type="string" update="true"/> <set cascade="all" inverse="true" lazy="true" name="addressList" outer-join="false" table="address"> <key column="party_id"/> <one-to-many class="AddressImpl"/> </set> <bag batch-size="100" cascade="all" lazy="true" name="associatedObjects" outer-join="false"> <key column="master_object_id"/> <one-to-many class="ObjectAssociationImpl"/> </bag> <bag batch-size="100" cascade="all" lazy="true" name="associations" outer-join="false"> <key column="associated_object_id"/> <one-to-many class="ObjectAssociationImpl"/> </bag> <subclass discriminator-value="OT4" name="HumanImpl" proxy="HumanImpl"> <property column="name_human_first" insert="true" name="firstName" type="string" update="true"> <meta attribute="finder">findByFirstName</meta> </property> <property column="name_human_middle" insert="true" name="middleName" type="string" update="true"> <meta attribute="finder">findByMiddleName</meta> </property> <property column="name_human_last" insert="true" name="lastName" type="string" update="true"> <meta attribute="field-description">The last name of the person.</meta> <meta attribute="finder">findByLastName</meta> </property> <property column="name_human_prefix" insert="true" name="namePrefix" type="string" update="true"/> <property column="name_human_suffix" insert="true" name="nameSuffix" type="string" update="true"/> <property column="description" insert="true" name="description" type="string" update="true"/> <property column="job_title" insert="true" name="title" type="string" update="true"/> </subclass>
ObjectAssociation.hbm.xml <class name="ObjectAssociationImpl" polymorphism="implicit" proxy="ObjectAssociationImpl" table="object_association"> <id column="object_association_id" name="objectAssociationID" type="string" unsaved-value="null"> <generator class="uuid.hex"/> </id> <many-to-one class="ObjectTypeImpl" column="object_type_id" name="objectType"/> <any id-type="string" name="masterObject"> <column name="master_object_class"/> <column name="master_object_id"/> </any> <any id-type="string" name="associatedObject"> <column name="associated_object_class"/> <column name="associated_object_id"/> </any> </class>
Code between sessionFactory.openSession() and session.close(): logger.debug( "SAVING COPY:" + object.toString() ); session = getSession(); trans = session.beginTransaction(); session.saveOrUpdateCopy( object ); trans.commit();
Session closed by the HTTP filter
Full stack trace of any exception that occurs: 2005-12-07 11:10:49,641 [http-8080-Processor25] DEBUG org.hibernate.engine.Cascades$5.cascade: 153 - cascading to saveOrUpdate: ObjectAssociationImpl 2005-12-07 11:10:49,642 [http-8080-Processor25] DEBUG org.hibernate.engine.Cascades$24.isUnsaved: 575 - id unsaved-value strategy NULL 2005-12-07 11:10:49,646 [http-8080-Processor25] DEBUG org.hibernate.event.def.AbstractSaveEventListener.getEntityState: 414 - detached instance of: ObjectAssociationImpl 2005-12-07 11:10:49,648 [http-8080-Processor25] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached: 200 - updating detached instance 2005-12-07 11:10:49,649 [http-8080-Processor25] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate: 246 - updating [ObjectAssociationImpl#8a818b970805c715010805fc9a750005] 2005-12-07 11:10:49,651 [http-8080-Processor25] ERROR org.hibernate.LazyInitializationException.<init>: 19 - could not initialize proxy - the owning Session was closed org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84) at org.hibernate.impl.SessionImpl.bestGuessEntityName(SessionImpl.java:1436) at org.hibernate.type.AnyType.getPropertyValues(AnyType.java:246) at org.hibernate.event.def.AbstractVisitor.processComponent(AbstractVisitor.java:85) at org.hibernate.event.def.ReattachVisitor.processComponent(ReattachVisitor.java:45) at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:110) at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:64) at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:58) at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:129) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:267) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69) at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468) at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154) at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771) at org.hibernate.engine.Cascades.cascade(Cascades.java:720) at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895) at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792) at org.hibernate.engine.Cascades.cascade(Cascades.java:720) at org.hibernate.engine.Cascades.cascade(Cascades.java:847) at org.hibernate.engine.Cascades.cascade(Cascades.java:819) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.cascadeOnUpdate(DefaultSaveOrUpdateEventListener.java:316) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:299) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69) at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468) at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:463)
Name and version of the database you are using: MySQL 5.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|