• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate 2: getting lazy exception after trying to get a collection from a transient object

 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am getting lazy exception after trying to get a collection property from a transient object. This object was retrieved in a session that is already closed. So I opened the new session and did sess.update on this object but this didn't help.
what did help is getting the id of this object and doing.

This is no elegant in my opinion. So why sess.update does not help and is there any other way then retrieving the object again by it;s id?

Thanks.
 
Andreas Erber
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John Landon,

the Session.get() method returns an uninitialized proxy of the requested entity. To not cause a LazyInitializationException you could "touch" the proxy within the session by deliberately calling one of its methods which forces proxy initialization. You could also choose Session.load() which returns an initialized instance.

CU
Froestel
 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andreas Erber wrote:Hi John Landon,

the Session.get() method returns an uninitialized proxy of the requested entity. To not cause a LazyInitializationException you could "touch" the proxy within the session by deliberately calling one of its methods which forces proxy initialization. You could also choose Session.load() which returns an initialized instance.

CU
Froestel


thanks but load does not help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic