-->
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.  [ 2 posts ] 
Author Message
 Post subject: Lazy init. exception after ending transaction. Is correct?
PostPosted: Thu Nov 14, 2013 11:33 am 
Newbie

Joined: Wed Aug 07, 2013 11:54 am
Posts: 5
My application has in the meantime grown considerably so I cannot state on a 100% that this is the reason, but I have an entity which is loaded in a session, then the same session inits a transaction and after undertaking the task it finishes the transaction, all within the same session of course. Does it make sense that the entity loaded before initiating the transaction gets somehow disconnected from the persistence context, then I am not being able to retrieve some of its related lists (onetomany relationships) due to a LazyInitializationException, having no other solution but to refresh the reference in the very same session.

I presume the reason for that is having finished and comitted a transaction on the session previously, but please could an expertise hibernate user confirm that?

Many thanks in advance for your help?

Regards,

Carlos.


Top
 Profile  
 
 Post subject: Re: Lazy init. exception after ending transaction. Is correct?
PostPosted: Tue Nov 19, 2013 4:44 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
the reason for that is having finished and comitted a transaction on the session previously,


No, that's not the actual reason.
It's not the transaction state, it's the session state which matters.
LazyInitializationException raises when the session is not open anymore.
Explained in detail:
1. You open a session session1 and read a persistent object obj1 with a lazy OneToMany-relation.
In such case the collection which represents the OneToMany-relation get not filled immediately,
the collection does only keep a reference to session1, in order that he can fill the collection when necessary.
2. In some way you get to a point where you close session1 (probably without intention).
3. Now you access in some way the collection of obj1. The collection now tries to retrieve the associated elements by using session1 but detects that session1 is not open anymore -> LazyInitializationException


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.