GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes set lazy to false in runtime in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "set lazy to false in runtime in Hibernate" Watch "set lazy to false in runtime in Hibernate" New topic
Author

set lazy to false in runtime in Hibernate

Mohamad Norouzi
Greenhorn

Joined: Oct 12, 2004
Posts: 18
Hi all

I have two table one is master and other is detail and a class
that contains a list refer to detail.

class Master {
....
private List details;
}

I set lazy to true in one-to-many relation (lazy="true")

so when I going to load details ( master.getDetails(); )
an exception occures.
I want to know, is there any way to set lazy to false in runtime or manually when I want.

thank u in advance

best wishes
[ August 20, 2005: Message edited by: mohammad norouzee ]

<a href="http://pixelshot.wordpress.com" target="_blank" rel="nofollow">http://pixelshot.wordpress.com</a><br /><a href="http://brainable.blogspot.com" target="_blank" rel="nofollow">http://brainable.blogspot.com</a>
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Most probably you will want to lazily access associations, unless it makes sense to always return your list of details. That being said, the lazy initialization should occur when the associated property is first accessed, i.e. when you call getDetails(). What is the exception you are seeing?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mohamad Norouzi
Greenhorn

Joined: Oct 12, 2004
Posts: 18
I am using spring framework and DAO pattern and in springframework there is a method --> getHibernateTemplate() and with this method we select or save and object but this framework handle the transactions itself so when I am going to load a lazy collection an error occurred and says that session was closed and can not load a lazy object.

help me please
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

In Spring, I think I am right in saying you don't need to worry about Hibernate sessions if you use a HibernateTemplate to wrap the Hibernate nuts-and bolts, assuming you are using this HibernateTemplate from within a Spring-driven or JTA transaction. If your transaction has ended, the session is closed. Are you accessing this object within the same transaction you got it?
 
Don't get me started about those stupid light bulbs.
 
subject: set lazy to false in runtime in Hibernate