wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes Lazy Initialization Exception with JSF 2 and EJB 3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Lazy Initialization Exception with JSF 2 and EJB 3" Watch "Lazy Initialization Exception with JSF 2 and EJB 3" New topic
Author

Lazy Initialization Exception with JSF 2 and EJB 3

Robert Siqueira
Ranch Hand

Joined: Jan 21, 2008
Posts: 37
Hi, I'm getting a Lazy exception in this scenario:

I have a ManagedBean -> EJB -> DAO.

The method in EJB calls a merge to load the collection and it works perfect. If I inspect the object in a debug mode, i can see the List loaded.

The problem is, when the EJB returns the object to my MB, I cant see the list loaded and i get a LazyInitializationException in my jsg page.

Why the list is loaded in EJB but when return to my MB the list is not loaded anymore ?

Regards,

Robert Siqueira

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Once the ejb method ends the container will also end the associated transaction. Thus making all the entities detached. Then when you try to use variables of the entities which aren't loaded it will throw an LazyInitializationException.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
GeeCON Prague 2014
 
subject: Lazy Initialization Exception with JSF 2 and EJB 3