8 Replies Latest reply on Aug 31, 2011 3:34 PM by Scott Marlow

    Seam 2 / Hibernate 3 / Entity Manager Factory issue

    guinotphil Apprentice

      Hello,

       

      I'm having some trouble to access to the Entity Manager Factory from a Seam 2 application that I want to deploy on JBoss AS 7.

       

      My persistences beans are in a jar located in ear/lib, and with the following META-INF/persistence.xml

       

      <?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_2_0.xsd"

                   version="2.0">

       

      <persistence-unit name="entityManagerFactory" transaction-type="JTA">

         <provider>org.hibernate.ejb.HibernatePersistence</provider>

          <jta-data-source>java:jboss/datasources/MyDS</jta-data-source>

          <properties>   

              <property name="jboss.as.jpa.providerModule" value="org.hibernate:3"/>

       

              <property     name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />

       

               <property    name="jboss.entity.manager.factory.jndi.name"

                               value="java:app/myEntityManagerFactory" />

      ...

       

       

      Of course, the Oracle datasource MyDS is defined in the standalone.xml file...

       

      The ear contains a war and jboss-seam.jar modules. In the war's WEB-INF the components.xml has the following definitions:

      <component class="org.jboss.seam.transaction.EjbSynchronizations" jndi-name="java:app/jboss-seam/EjbSynchronizations"/>

      <component name="org.jboss.seam.persistence.persistenceProvider" class="mypatch.seam.persistence.HibernateJpa2PersistenceProvider"/>

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

       

      The HibernateJpa2PersistenceProvider class refers to a provider created as said on this blog: http://ctpjava.blogspot.com/2010/07/using-seam-2-with-jpa-2.html

       

       

      My trouble is that when I'm deploying, I get the following exception;

       

      java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:app/MyEntityManagerFactory

      Caused by: javax.naming.NameNotFoundException: Name 'myEntityManagerFactory' not found in context ''

          at org.jboss.as.naming.util.NamingUtils.nameNotFoundException(NamingUtils.java:109)

          at org.jboss.as.naming.InMemoryNamingStore$NodeTraversingVisitor.visit(InMemoryNamingStore.java:368)

          at org.jboss.as.naming.InMemoryNamingStore$ContextNode.accept(InMemoryNamingStore.java:307)

          at org.jboss.as.naming.InMemoryNamingStore.lookup(InMemoryNamingStore.java:162)

          at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:173)

          at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:47)

          at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)

          at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_22]

          at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:241) [jboss-seam.jar:]

          ... 51 more

       

      When I look at the admin console, in the naming view, I can see my datasources as well as my ejbs but I cannot find the entity manager factory.

       

      I've read somewhere that JBoss 7 does no longer make a JNDI binding of the entity manager factory from the persistence.xml. So, how do I refer to it on my components.xml ? How can seam 2 access to the entity manager factory ?

       

      Thanks a lot for your help.