-->
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: Problems with lazy="false"
PostPosted: Mon Apr 17, 2006 2:57 pm 
Newbie

Joined: Mon Apr 17, 2006 2:39 pm
Posts: 1
Hi,

I have class which contains a map that should always be loaded and present, also when the object is detached and passed to the web-tier. Therefore I added lazy="false" and fetch="join" to the <map> element in the mapping file.

This approach works if I query the object, and then detach it (i.e. close the session).

Unfortunately it does not work when the object is loaded by id (session.load(class,id)) or retrieved by navigating an association. In this situation the lazy="false" is ignored and the map is not fetched from the database. In the end a LazyInitializationException gets thrown.

Current workaround is to use Hibernate.initalize() in the DAO, but, due to the fact that the map in this class should alway be present and also provided in detached form, this approach is error prone (easy to forget the call) and probably slower than necessary.

Any ideas?

Thanks,
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 7:41 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Sounds like you're doing all the right things. You could switch to using the Open Session In View pattern to avoid all that, but you don't have to.

All fetch="???" and lazy="???" attributes are at best hints. They apply only in certain circumstances, and can be overridden in most cases. Your data access layer will have to ensure that the map is initialized every time, unless you keep the session open until all necessary data has been retrieved.


Top
 Profile  
 
 Post subject: Re: Problems with lazy="false"
PostPosted: Wed Apr 19, 2006 8:26 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 2:26 pm
Posts: 28
axelf wrote:
Unfortunately it does not work when the object is loaded by id (session.load(class,id)) or retrieved by navigating an association. In this situation the lazy="false" is ignored and the map is not fetched from the database. In the end a LazyInitializationException gets thrown.


Probably the class itself is being lazily-loaded. Set lazy="false" on the <class> element.


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.