-->
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.  [ 7 posts ] 
Author Message
 Post subject: Session.refresh(object) sets session=null of child list
PostPosted: Thu Mar 29, 2007 10:21 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.2

Mapping documents:
parent:
<list
name="childRequirements"
lazy="extra"
inverse="true"
cascade="persist,evict,delete,replicate,lock,save-update"
>

<key column="parent_requirement_id"></key>

<index column="sequence"/>

<one-to-many class="com.seqis.kltm.model.db.project.Requirement"/>

</list>


child:
<many-to-one
name="parentRequirement"
class="com.seqis.kltm.model.db.project.Requirement"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="parent_requirement_id"
/>


Name and version of the database you are using: MySQL 5



Code:
//creating a parent
Requirement req = new Requirement("parent");
SessionFactory f = KLTMContext.getSessionFactory("test_hibernate");
Session s1 = f.openSession();
Transaction tx = s1.beginTransaction();
s1.saveOrUpdate(req);
tx.commit();
s1.close();

//adding a child   
s1 = f.openSession();
Requirement child = new Requirement("child");
Requirement req2 = (Requirement) s1.merge(req);
tx = s1.beginTransaction();
req2.addChildRequirement(child);
s1.saveOrUpdate(child);
tx.commit();
s1.close();
   
//loading the parent and refreshing parent and child   
s1 = f.openSession();
req = (Requirement) PersistentModel.narrow(s1.load(Requirement.class, new Long(req2.getObjectId())));
s1.refresh(req);
child = (Requirement) req.getChildRequirements().get(0);
s1.refresh(child);
.close();


after the child was refreshed, the child's child list has no session set.
anybody knows why?

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 7:00 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
What do you mean byb the child's child's session is not set? Session is not associated to an entity. Entity has no knowledge that it's being managed by a session.

Maybe you could re-explain your issue?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 7:15 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
Hello!
The child has also a list of childs (the child is a parent too, but the list is empty in this case).
After loading the parent and getting the child of the parents child list, the child has a org.hibernate.collections.persistentlist. this list has a property "session" which holds a SessionImpl Object (the session is open). After refreshing the child, the property "session" is null.
A strange thing is, that the childs PersistentList has the same JVM id before and after refreshing. The PersistentList of the parent is a new Object after refreshing (the JVM id changes).

lg


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 7:29 am 
Newbie

Joined: Mon Nov 13, 2006 4:55 am
Posts: 3
lazy="false"

_________________
WBR
Eugene Veselov


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 7:44 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
this lists will get very huge, so lazy="false" can not be the best solution.
lg


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 8:02 am 
Newbie

Joined: Mon Nov 13, 2006 4:55 am
Posts: 3
it is the answer on your question. Probably, when you refresh container object, all included "lazy" elements becomes uninitialized. It is standart behaviour of lazy elements.

_________________
WBR
Eugene Veselov


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 8:08 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
could you explain me then, why the parent and the child are acting different? both are objects from the same class, but the list of the parent has the session set after the refresh and the childs list has not.

i understand, that the list is uninitialized after a refresh because of lazy="true", but when it has no session set, how am i able to initialize it?


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