6 Replies Latest reply on Sep 13, 2007 10:56 AM by Alex Savitsky

    LazyInitializationExceptions are staying

    l j Newbie

      I use the following combination of tools:
      Seam 1.2 GA
      Apache MyFaces
      EJB3
      hibernate-commons-annotations 3.3.0.ga
      hibernate-validator3.0.0.ga
      com.sun.facelets 1.1.12
      org.ajax4jsf 1.1.1
      org.richfaces 3.0.1
      jboss-ejb3-all 3.0.0
      hibernate 3.0.0

      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
      @PersistenceContext(type=PersistenceContextType.EXTENDED)
      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"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
      version="1.0">
      <persistence-unit name="atinvestorDb">
      org.hibernate.ejb.HibernatePersistence
      <jta-data-source>java:/AtInvestorMySqlDS</jta-data-source>





      <!-- 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"/-->


      </persistence-unit>


      components.xml (located in WEB-INF of web WAR)
      ===========
      ...
      <core:managed-persistence-context name="entityManager"
      auto-create="true"
      persistence-unit-jndi-name="java:/atinvestorEntityManagerFactory" />
      ...

      faces-config.xml (located in WEB-INF of web WAR)
      ===========
      ...

      <phase-listener>org.jboss.seam.jsf.TransactionalSeamPhaseListener</phase-listener>

      ...


      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) ?

      Thanks beforehand.

      Michel