2 Replies Latest reply on Dec 13, 2013 2:33 PM by gebuh

    jboss7, hibernate 3 entityManagerFactory not found

    gebuh

      I'm migrating a Seam 2 application to JBoss7.1.1 I have JSF1.2 and Hibernate 3 set in the jboss-deployment-structure.xml but when I get to the point in the deployment where 2nd level caching is initiated I'm getting:

       

      Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener: org.jboss.seam.InstantiationException: Could not instantiate Seam component: org.jboss.seam.cache.cacheProvider
      ...
      
      Caused by: java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:/EntityManagerFactories/MyWar
      
      ...
      Caused by: javax.naming.NameNotFoundException: EntityManagerFactories/MyWar -- service jboss.naming.context.java.EntityManagerFactories.MyWar
          at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
          at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
          at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113)
          at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
          at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_40]
          at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:257) [jboss-seam.jar:2.2.2.Final]
      
      

       

      I'm using Hibernate 3.3.1 so my persistence.xml has

      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
      
      

       

      I think this might be related to how ehcache sets up transaction management (it's supposed to happen automagically)

      <!-- TransactionManagerLookup configuration
          ======================================
          This class is used by ehcache to lookup the JTA TransactionManager use in the application
          using an XA enabled ehcache. If no class is specified then DefaultTransactionManagerLookup
          will find the TransactionManager in the following order
      
           *GenericJNDI (i.e. jboss, where the property jndiName controls the name of the
                          TransactionManager object to look up)
           *Bitronix
           *Atomikos
      
          You can provide you own lookup class that implements the
          net.sf.ehcache.transaction.manager.TransactionManagerLookup interface.
        
      
          <transactionManagerLookup class="net.sf.ehcache.transaction.manager.DefaultTransactionManagerLookup"
                                    properties="jndiName=java:/TransactionManager" propertySeparator=";"/>
      -->
      
      

       

      So I'm letting ehcache configure itself, is there something else I need to do to make this work?

      this is eh-cache 2.7.1

        • 1. Re: Configuring ehcache with jboss7 and hibernate 3
          gebuh

          So it appears the ehcache issue is a red herring, it accesses the em right after deployment.  It's an entityManager problem, it's not getting created.

          I've tried a bunch of stuff to get it working, right now I have:

          Persistence.xml:

           

          <persistence-unit name="MyPU" transaction-type="JTA">
          ...
          <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/MyPUEntityManagerFactory"/>
          

          components.xml:

          <core:init debug="@debug@" jndi-pattern="java:app/MyPU/#{ejbName}/local"/>
          <persistence:managed-persistence-context name="entityManager" auto-create="true"
          persistence-unit-jndi-name="java:jboss/MyPUEntityManagerFactory"/>
          

           

           

          But I still get:

          ...
          Caused by: java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:jboss/MyPUEntityManagerFactory
          Caused by: javax.naming.NameNotFoundException: MyPUEntityManagerFactory -- service jboss.naming.context.java.jboss.MyPUEntityManagerFactory
          

           

          What am I doing wrong?

          • 2. Re: Re: Configuring ehcache with jboss7 and hibernate 3
            gebuh

            After spending days banging my head against the wall I got it working - but I must still be missing something because there are several Seam 2 migrations out there and this wasn't mentioned (AFAIK).  Someone please feel free to enlighten me.

            So from here I learned that:

            By default JBoss AS7 does not bind the entity manager factory to JNDI.

            However, you can explicitly configure this in the persistence.xml of your application

            by setting the jboss.entity.manager.factory.jndi.name property.

            The value of that property should be the JNDI name to

            which the entity manager factory should be bound.

            I had that:

            <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/MyPUEntityManagerFactory"/>


            However a few lines above that it says:

            jboss.as.jpa.managed can be set to false to disable container managed JPA access to the persistence unit. 

            The default is true, which enables container managed JPA access to the persistence unit. 

            This is typically set to false for Seam 2.x + Spring applications.

             

            I think this is for Hibernate 3.3 issues and I had that set also:

            <property name="jboss.as.jpa.managed" value="false"/>
            

             

            So I thought I was creating my entity manager and naming it.

            The above coupled with my settings in components.xml:

            <persistence:managed-persistence-context name="entityManager" auto-create="true"  
            persistence-unit-jndi-name="java:jboss/MyPUEntityManagerFactory"/>
            
            

            had Seam looking for a persistence context that had not been created.

             

            The solution was to delete the jboss.entity.manager.factory.jndi.name property from persistence.xml and let Seam handle the creation:

            <persistence:entity-manager-factory name="MyPUEntityManagerFactory" persistence-unit-name="MyPU" />
            <persistence:managed-persistence-context name="entityManager" auto-create="true" 
            entity-manager-factory="#{MyPUEntityManagerFactory}" />
            

             

            I would welcome more input on this.

            On to the next problem - why am I seeing hibernate 4 loading when I excluded it so I could continue to use hibernate 3.3?