12 Replies Latest reply on Apr 16, 2012 2:26 PM by brandondash

    Another Seam 2 / JNDI / Entity Manager Factory issue

    brandondash

      At first I thought I had the same issue as was solved here https://community.jboss.org/message/621640#621640

       

      Having gone through the steps outlined in that thread I made no progress. Perhaps I can get some help for my specific issue. Here are the relevant snippets.

       

      standalone.xml

              <subsystem xmlns="urn:jboss:domain:datasources:1.0">

                  <datasources>

                      <datasource jndi-name="java:jboss/datasources/postgresDS" pool-name="postgresDS" enabled="true" use-java-context="true">

                          <connection-url>jdbc:postgresql://localhost:5432/medalea</connection-url>

                          <driver-class>org.postgresql.Driver</driver-class>

                          <driver>postgresql</driver>

                          <security>

                              <user-name>MY_USER_ACCOUNT</user-name>

                              <password>MY_PASSWORD_HERE</password>

                          </security>

                      </datasource>

                      <drivers>

                          <driver name="postgresql" module="org.postgresql">

                              <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>

                          </driver>

                          <driver name="h2" module="com.h2database.h2">

                              <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>

                          </driver>

                      </drivers>

                  </datasources>

              </subsystem>


       

      persistence.xml

      <persistence-unit name="medalea">

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

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

                          <properties>

                                    <property name="hibernate.dialect" value="org.hibernatespatial.postgis.PostgisDialect" />

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

                               value="java:app/medaleaEntityManagerFactory" />

                </properties>

      </persistence-unit>

       

      components.xml

          <core:init jndi-pattern="java:app/medalea.jar/#{ejbName}" debug="true" distributable="false"/>

          <transaction:ejb-transaction/>

       

          <security:identity authenticate-method="#{authenticator.authenticate}"/>

       

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

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

       

          <persistence:managed-persistence-context auto-create="true" name="entityManager"

                persistence-unit-jndi-name="java:app/medaleaEntityManagerFactory" />

       

      stacktrace

      Caused by: java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:app/medaleaEntityManagerFactory

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

              at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:78) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:107) [jboss-seam.jar:2.2.0.GA]

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_27]

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_27]

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_27]

              at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_27]

              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.callComponentMethod(Component.java:2249) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.unwrap(Component.java:2275) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.getInstance(Component.java:2041) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.getInstance(Component.java:1983) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.getInstance(Component.java:1977) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2349) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.getValueToInject(Component.java:2301) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.injectAttributes(Component.java:1736) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.inject(Component.java:1554) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.util.Work.workInTransaction(Work.java:47) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) [jboss-seam.jar:2.2.0.GA]

              at org.minenet.action.nav.NavigationManager_$$_javassist_seam_3.onCreate(NavigationManager_$$_javassist_seam_3.java) [medalea.jar:v1.0.0-i1-b6.2]

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_27]

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_27]

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_27]

              at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_27]

              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.callComponentMethod(Component.java:2249) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.callCreateMethod(Component.java:2172) [jboss-seam.jar:2.2.0.GA]

              at org.jboss.seam.Component.newInstance(Component.java:2132) [jboss-seam.jar:2.2.0.GA]

              ... 13 more

      Caused by: javax.naming.NameNotFoundException: medaleaEntityManagerFactory -- service jboss.naming.context.java.app.medalea.medaleaEntityManagerFactory

              at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)

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

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

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

              at javax.naming.InitialContext.lookup(InitialContext.java:392) [rt.jar:1.6.0_27]

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

              ... 51 more

       



        • 1. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
          smarlow

          Are you using the latest AS7 version?  If not upgrade to the latest (7.1.1) and try again.

           

          If your already on the latest AS7 version, try using a global name (e.g. "java:global/medaleaEntityManagerFactory" or java:jboss/medaleaEntityManagerFactory) to see if that helps.  If it does help, we still need to know why the "app" namespace isn't working for you.

          • 2. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
            brandondash

            I was on 7.1.0.Final and have upgraded.

             

            This issue is happening for the global namespace as well

             

            Caused by: javax.naming.NameNotFoundException: medaleaEntityManagerFactory -- service jboss.naming.context.java.global.medaleaEntityManagerFactory

                    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:123)

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

                    at javax.naming.InitialContext.lookup(InitialContext.java:392) [rt.jar:1.6.0_27]

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

                    ... 51 more

             

             

            I changed both components.xml and persistence.xml. Here are the pertinent lines as they stand currently:

             

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

             

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

             

             

            Everything looks to be on the up and up to me (this is a migration from jbas4.2.3 and obviously works fine there). I am at a loss for what to try next. Could it be  the lookup is failing because the persistence-unit is never properly created? I keep looking at components.xml but perhaps persistence.xml is my problem?

             

            This is frustrating. :[


            • 3. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
              brandondash

              More information that may or may not help:

               

              Our app is running with hibernate 3.3. the JPA reference guide implies that you can only carry 3.5 or greater with your app. Reference here

               

              "AS 7.0.1 allows the packaging of Hibernate 3.5 (or greater) persistence provider jars with the application." https://docs.jboss.org/author/display/AS7/JPA+Reference+Guide

               

              I noticed you did some work with older hibernate 3.x discussed here https://issues.jboss.org/browse/AS7-1583

               

              So... in the interest of completeness here is my full persistence block

               

              <!-- Persistence deployment descriptor for dev profile -->

              <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="medalea">

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

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

                                  <properties>

                                            <property name="hibernate.dialect" value="org.hibernatespatial.postgis.PostgisDialect" />

                                            <property name="hibernate.hbm2ddl.auto" value="none" />

                                            <property name="hibernate.show_sql" value="true" />

                                            <property name="hibernate.format_sql" value="true" />

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

                                                      value="java:global/medaleaEntityManagerFactory" />

                                            <property name="hibernate.ejb.event.post-insert"

                                                      value="org.hibernate.envers.event.AuditEventListener"/>

                                            <property name="hibernate.ejb.event.post-update"

                                                      value="org.hibernate.envers.event.AuditEventListener"/>

                                            <property name="hibernate.ejb.event.post-delete"

                                                      value="org.hibernate.envers.event.AuditEventListener"/>

                                            <property name="hibernate.ejb.event.pre-collection-update"

                                                      value="org.hibernate.envers.event.AuditEventListener"/>

                                            <property name="hibernate.ejb.event.pre-collection-remove"

                                                      value="org.hibernate.envers.event.AuditEventListener"/>

                                            <property name="hibernate.ejb.event.post-collection-recreate"

                                                      value="org.hibernate.envers.event.AuditEventListener"/>

                          <property name="org.hibernate.envers.doNotAuditOptimisticLockingField"

                              value="false"/>

                                            <property name="hibernate.jdbc.batch_size" value="100" />     

                                            <property name="hibernate.search.default.directory_provider"

                                               value="org.hibernate.search.store.FSDirectoryProvider"/>

                          <property name="hibernate.search.default.indexBase" value="${jboss.server.data.dir}/medalea/lucene"/>

               

               

                                  </properties>

                        </persistence-unit>

              </persistence

               

               

               

              Edit: It would appear hibernate 3.3 has known issues and that I should upgrade, but we're still in JPA1 land. Guidance?

              • 4. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
                smarlow

                Lets try one more thing, the AS7 testsuite has a test with "java:global/medaleaEntityManagerFactory" set to "myEMF" (which defaults to the JBoss global name space).  Try changing your setting to "medaleaEntityManagerFactory" and see what happens.  If that helps, you will have a workaround and we will have a better idea of what needs to be fixed.

                 

                Regarding the entity classes and why you should add them manually to your persistence.xml (only when using Hibernate 3.3) is due to a deployment problem.  When Hibernate 3.3 looks for entity classes on AS7, it won't find them.  Hibernate 3.5/3.6 has been modified to address this problem.  If you happen to be on the product stream, I believe a fix for that will be available.

                • 5. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
                  jaikiran

                  By the way, when exactly does this exception occur? During deployment time or when you try to access your application? If it's during deployment time then it might even be a case of the lookup being done before the entity manager factory is bound to JNDI - i.e. a case of dependency not being setup correctly. The stacktrace you posted in your two posts don't look like complete stacktraces, so I can't say for sure.

                  • 6. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
                    smarlow

                    I meant that the AS7 testsuite has a test with the "jboss.entity.manager.factory.jndi.name" property set to "myEMF" (which uses the "java:jboss" global namespace).

                     

                    As a test, try setting the "jboss.entity.manager.factory.jndi.name" property to "medaleaEntityManagerFactory".  If that works, we can then find the bug with the other name space choices.

                     

                    Scott

                    • 7. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
                      brandondash

                      @Scott

                       

                      I figured that was what you meant. I downloaded the test suite and will give it a shot this morning.

                      • 8. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
                        brandondash

                        @jaikiran

                         

                        This happens on startup of jboss. It absolutely could be a dependency issue; however, I don't know what piece of configuration I would check to see. Guidance?

                        • 9. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
                          jaikiran

                          If you attach the entire server.log containing the exception stacktrace, then that will help us understand what triggers this action at deployment time and what dependency needs to be set by whom and where.

                          • 10. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
                            brandondash

                            I think it's safe to ignore the stacktrace early on in the log. One of our schemas has an errant import that needs to be removed.

                            • 11. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
                              smarlow

                              Brandon,

                               

                              Did you use "medaleaEntityManagerFactory" for the jndi name or "java:/medaleaEntityManagerFactory"?  For the test, you should use "medaleaEntityManagerFactory".

                               

                              Scott

                              • 12. Re: Another Seam 2 / JNDI / Entity Manager Factory issue
                                brandondash

                                Thank you both for your assistance in this matter. As it turns out that problem had nothing to do with JNDI. I had a JaxB compatibility issue that was wreaking havoc on the deployment. Once I introduced an older JaxB module the roadblock was cleared.

                                 

                                I have a hundred other problems, but nothing to run up the flagpole yet.