-->
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.  [ 4 posts ] 
Author Message
 Post subject: updating the persistent state of a detached instance
PostPosted: Wed Dec 07, 2005 1:26 pm 
Beginner
Beginner

Joined: Tue Dec 28, 2004 11:30 am
Posts: 32
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:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 4:42 pm 
Beginner
Beginner

Joined: Tue Dec 28, 2004 11:30 am
Posts: 32
Any help on this one guys ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 12:42 pm 
Beginner
Beginner

Joined: Tue Dec 28, 2004 11:30 am
Posts: 32
Does anybody have any thoughts regarding this problem ??
is this something supported ? Am i doing the right thing

Thank you


Top
 Profile  
 
 Post subject: Maybe this helps you
PostPosted: Mon Dec 12, 2005 7:17 pm 
Newbie

Joined: Mon Dec 12, 2005 7:07 pm
Posts: 1
i am not quite sure, but is it possible that your mixing hibernate 2 and 3?
i have made this experience and it seemed working, but wasn´t really stable.

i fixed this by using merge() instead of saveOrUpdateCopy(), but watch it - i think merge() won´t save new objects !

hope this helps. oP


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.