I use the following combination of tools:
Seam 1.2 GA
I want to make use of Seam-managed persistence context with JPA; the problem I get is that lazy loading (FetchType.LAZY) isn't working ; if I use FetchType.EAGER everything works correctly.
I get the following error:
org.hibernate.LazyInitializationException: failed to lazily intialize a collection of role: .....
I followed the tutorial within the SEAM tutorial
I have the following configuration of a project including 2 subprojects, which are packed in seperate jars.
Jars/wars in total ear project:
1. JAR ejb project containing the domain objects, service layer (stateless ejb3 beans) and controller layer (statefull ejb3 beans); in this jar the persistence.xml is located in the META-INF directory
2. JAR commons project containing helper classes (in this jar the entitymanager is injected using
private EntityManager entityManager
3. WAR web project
Overview of configuration files:
persistence.xml (located in META-INF directory van ejb jar)
<?xml version="1.0" encoding="UTF-8"?>
<!-- These are the default for JBoss EJB3, but not for HEM: -->
<!-- Put the EntityManagerFactory into JNDI so we can use it manually in tests -->
<!--property name="jboss.entity.manager.jndi.name" value="java:/atinvestorEntityManager"/-->
components.xml (located in WEB-INF of web WAR)
faces-config.xml (located in WEB-INF of web WAR)
Can someon help me why I don't get lazy loading to work with this configuration.
- Can it be that the problem is in the fact that the injection of the EntityManager is within another JAR then where the persistency unit residence (and therefore the persistence.xml file is located) ?
I tested the LAZY loading functionality on the dvdstore examples project delivered with the JBoss SEAM 1.2GA distribution, but there lazy loading ONLY works for OneToOne relations, and it is NOT working for ManyToMany relations.
But by default the ManyToMany relation within the dvdstore application is put to EAGER loading instead of LAZY loading.
I changed this to FetchType = LAZY, and then I get the same exception as I have on my application (LazyInitializaionException).
Therefore I think that LAZY loading is only working for OneToOne relations.
Is this correct ??
Nothing to do with Seam, ask on the hibernate forum.
Can you please give me a more constructive answer including an explanation and where the problem is residing within hibernate.
I think that Pete means that the constructive answer and where the problem is should be sought in the hibernate forum....
Try injecting your persistence context using @In - I believe that lazy loading only works with Seam-managed PC (the one injected via @PersistenceContext is not Seam-managed). Of course, you'll need to setup the SMPC properly as well... (look at examples)