Hello, how are you?
In the post today we will talk about the common LazyInitializationException error. We will see four ways to avoid this error, the advantage and disadvantage of each approach and in the end of this post, we will talk about how the EclipseLink handles this exception.
To see the LazyInitializationException error and to handle it, we will use an application JSF 2 with EJB 3.
Topics of the post:
- Page 3: Understanding the problem, Why does LazyInitializationException happen?
- Page 4: Load collection by annotation
- Page 5: Load collection by Open Session in View (Transaction in View)
- Page 6: Load collection by Stateful EJB with PersistenceContextType.EXTENDED
- Page 7: Load collection by Join Query
- Page 8: EclipseLink and lazy collection initialization
At the end of this post you will find the source code to download.
Attention: In this post we will find an easy code to read that does not apply design patterns. This post focus is to show solutions to the LazyInitializationException.
The solutions that you will find here works for web technology like JSP with Struts, JSP with VRaptor, JSP with Servlet, JSF with anything else.
The only page code that does not apply to JSE (usually Desktop applications) is the Page 6 with EJB.