• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

set lazy to false in runtime in Hibernate

 
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 ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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
Hibernate Eclipse IDE 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?
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!