-->
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.  [ 3 posts ] 
Author Message
 Post subject: Lazy Initialization Problem
PostPosted: Wed Jun 11, 2008 1:03 am 
Newbie

Joined: Wed Jun 11, 2008 12:52 am
Posts: 1
Hi ,
Facing Lazy Initialization problem while trying to fetch child records.(Having child properitiess as Set) in POJO


Top
 Profile  
 
 Post subject: Re: Lazy Initialization Problem
PostPosted: Wed Jun 11, 2008 4:14 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
Sathia wrote:
Hi ,
Facing Lazy Initialization problem while trying to fetch child records.(Having child properitiess as Set) in POJO


Do you really believe anybody could give you an advice (other than RTF) reading this problem description? -:)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 9:39 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
The problem you are having is that you are obtaining your object within an open session, closing the session, and then trying to access the 'child-objects'. In order to access these child objects, it must either be done within an open Hibernate Session, or, you need to have the fetch type for the records set to eager.

My suggestion is to keep the session open longer, otherwise you'll need more transactions. So, don't close your session so quickly. There are a number of ways to do this. If it is a web application, you should take a look at the Open Session in View design pattern/best practice. With this design, you can open a session when a web based request comes in, and close it when the resposne goes out. Hibernate will only load the records it needs, and you will minimize the number of database transactions that are needed.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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