• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

set lazy to false in runtime in Hibernate

 
Mohamad Norouzi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mohamad Norouzi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic