-->
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.  [ 8 posts ] 
Author Message
 Post subject: LazyInitializationException - hibernate exception???
PostPosted: Sat Sep 09, 2006 12:05 pm 
Beginner
Beginner

Joined: Sun Oct 16, 2005 12:37 pm
Posts: 47
Location: Romania, Galati
I've started to work with JBOSS EJB 3.0 Embeddable. When I tried to get elements form lazy initialization colection, a org.hibernate.LazyInitializationException occured. Why that exception doesn't have a JSR-220 counterpart?? What can I do against this situation? I've read many comments on forums and google but all related with hibernate core, not with EJB3.0. I don't want to break the portability of my code.

Any helps and hints are very welcome.

Thx in advance. Regards JTONIC.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 10, 2006 5:52 pm 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
Well there is nothing with portability!
You've got this exception on JBoss, and some Oracle exception on Oracle AS, and some weblogic exception on Weblogic ....

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 11, 2006 8:43 am 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
because hibernate load the lists lazily by default, when you are trying to get the list, Hibernate will go to select from database at that time, and I think there is no session at that moment.

you can set the FetchMode of the list to FetchMode.EAGER or FetchMode.JOIN and disable lazy loading of hibernate for that list.

@Basic(fecth=FetchMode.JOIN)

Hope this help you

please send your full stack trace exception and also your class definitions for this situation.



Regards
Mohammad Norouzi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 15, 2006 8:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
JBoss Seam work around the problem in an elegant way

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 1:05 pm 
Beginner
Beginner

Joined: Mon Apr 03, 2006 2:41 am
Posts: 25
Location: Mauritius
Hi Emmanuel,

What do you mean with
Quote:
JBoss Seam work around the problem in an elegant way

please ?

I' working on Seam but I have defined my DAO classes as stateless beana which are called from the stateful session bean.

I'm always getting the org.hibernate.LazyInitializationException if i don't fetch the content in my HQL queries ( I haven't modify the annotations because I always hope I will be able to do the lazy fecthing working )

Any idea how to keep the session open when the entity manager is in a stateless bean ?

Thanks in advance for any feedback.

Christophe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 1:28 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The solution is really simple: If you want to keep the state of the persistence context across requests and/or during RENDER_RESPONSE, don't close the persistence context too early. In other words, if you want to keep state, why are you using a stateless component?

In Seam you'd use a Seam managed persistence context (@In EntityManager) in a stateful conversational component. You will never see a LIE again if you don't try to move entity objects between conversational components (which is an anti-pattern).

This should go to the Seam forum, so please bring this up there if you want to know how Seam works.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 1:32 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
In case this isn't clear: The @In EntityManager goes into your stateful component. As long as you call your stateless DAO component within a method that has a transaction, the transaction _and_ the persistence context will be propagated into the stateless component during the call.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 1:39 pm 
Beginner
Beginner

Joined: Mon Apr 03, 2006 2:41 am
Posts: 25
Location: Mauritius
Thanks a lot Christian, for both the clarity and the rapidity of your answer !


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