-->
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: Session management question
PostPosted: Wed Mar 15, 2006 2:45 am 
Newbie

Joined: Mon Feb 27, 2006 6:47 pm
Posts: 8
Do I need to keep the Session open while I traverse my object?

I get the following exception while working with my entity after retrieving it from the DB: org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed

I understand this happens because I closed the session which originally created my object and I'm now trying to access the asociated objects out of this session. Do I need to keep the session open all the time?

This are the steps of my code:
1) start session
2) create query
3) execute query
4) Assign result entity to a variable
5) close session
6) create Value object from entity.

Step 6 requires navigating the associations and this causes the error .

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 10:48 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

1. Post your code (only the relevant parts).
2. Post your mappings (only the relevant parts).


Top
 Profile  
 
 Post subject: Re: Session management question
PostPosted: Wed Mar 15, 2006 10:58 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
acoronasz wrote:
Do I need to keep the session open all the time?



ofcourse not, you just need to keep it open long enough to get all the data you are going to use out of the database.

So, if you konw you're going to use a collection of an object, then Hibernate.initialize() it before you close the session and move on.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject: Re: Session management question
PostPosted: Thu Mar 16, 2006 8:18 am 
Beginner
Beginner

Joined: Thu Aug 19, 2004 5:36 am
Posts: 30
Location: Italy
acoronasz wrote:
Do I need to keep the Session open while I traverse my object?


Yes, unless you read from database all traversed objects before closing session.

Look to "Open Session in View pattern"


Delta


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.