8 Replies Latest reply on Mar 12, 2014 11:33 AM by Aaron Cordova

    Custom Service Implementation in EAR (javax.persistence.spi.PersistenceProvider)

    Aaron Cordova Newbie

      Hello,

       

      I am trying to deploy a custom PersistenceProvider service. My current implementation is intended to delegate to the hibernate PersistenceProvider (org.hibernate.jpa.HibernatePersistenceProvider). I have my PersistenceProvider implementation deploying to Wildfly correctly. Now I am having trouble getting the TransactionManager. Hibernate is failing to locate it using JNDI. What am I missing? Let me know if any more information is needed.

       

      Here is the callstack:

      Caused by: org.hibernate.engine.jndi.JndiException: unable to find transaction manager
        at org.hibernate.engine.transaction.jta.platform.internal.JBossAppServerJtaPlatform.locateTransactionManager(JBossAppServerJtaPlatform.java:62)
        at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.retrieveTransactionManager(AbstractJtaPlatform.java:104)
        at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.getTransactionManager(AbstractJtaPlatform.java:115)
        at org.hibernate.engine.transaction.jta.platform.internal.TransactionManagerBasedSynchronizationStrategy.canRegisterSynchronization(TransactionManagerBasedSynchronizationStrategy.java:56)
        at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.canRegisterSynchronization(AbstractJtaPlatform.java:148)
        at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.attemptToRegisterJtaSync(TransactionCoordinatorImpl.java:244)
        at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.pulse(TransactionCoordinatorImpl.java:275)
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1584)
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:210)
        at org.hibernate.jpa.internal.EntityManagerImpl.<init>(EntityManagerImpl.java:91)
        at org.hibernate.jpa.internal.EntityManagerFactoryImpl.internalCreateEntityManager(EntityManagerFactoryImpl.java:345)
        at org.hibernate.jpa.internal.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:313)
        at com.ultramain.persistence.manager.DelegatingEntityManagerFactory.createEntityManager(DelegatingEntityManagerFactory.java:34) [TechLogsCommonShared.jar:]
        at org.jboss.as.jpa.container.TransactionScopedEntityManager.createEntityManager(TransactionScopedEntityManager.java:177) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.as.jpa.container.TransactionScopedEntityManager.getOrCreateTransactionScopedEntityManager(TransactionScopedEntityManager.java:146) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.as.jpa.container.TransactionScopedEntityManager.getEntityManager(TransactionScopedEntityManager.java:78) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.as.jpa.container.AbstractEntityManager.find(AbstractEntityManager.java:198) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_45]
        at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_45]
        at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:401) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:42) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weldx.persistence.EntityManager$1987134959$Proxy$_$$_Weld$Proxy$.find(Unknown Source) [hibernate-jpa-2.1-api-1.0.0.Final.jar:]
        at com.ultramain.jee.manager.ReplicationContextQueryBean.findReplicationContext(ReplicationContextQueryBean.java:31) [ejb.jar:]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_45]
        at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_45]
        at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
        at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
        at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82) [wildfly-weld-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93) [wildfly-weld-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
        at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
        at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83) [wildfly-weld-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
        at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:251) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final]
        ... 269 more
      Caused by: org.hibernate.engine.jndi.JndiException: Unable to lookup JNDI name [java:jboss/TransactionManager]
        at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:117)
        at org.hibernate.engine.transaction.jta.platform.internal.JBossAppServerJtaPlatform.locateTransactionManager(JBossAppServerJtaPlatform.java:55)
        ... 330 more
      Caused by: javax.naming.NotContextException: java:jboss is not a subcontext
        at tyrex.naming.MemoryContext.internalLookup(Unknown Source) [tyrex.jar:1.0.3  December 2 2005 0125]
        at tyrex.naming.MemoryContext.lookup(Unknown Source) [tyrex.jar:1.0.3  December 2 2005 0125]
        at javax.naming.InitialContext.lookup(InitialContext.java:415) [rt.jar:1.7.0_45]
        at javax.naming.InitialContext.lookup(InitialContext.java:415) [rt.jar:1.7.0_45]
        at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:114)
        ... 331 more
      

       

      Here is my persistence.xml file:

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="2.0"
       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">
       <persistence-unit name="primary" transaction-type="JTA">
        <!-- If you are running in a production environment, add a managed data 
        source, this example data source is just for development and testing! -->
        <!-- The datasource is deployed as <EAR>/META-INF/wicket-ear-quickstart-ds.xml, 
        you can find it in the source at ear/src/main/application/META-INF/wicket-ear-quickstart-ds.xml -->
        <jar-file>TechLogsCommonShared.jar</jar-file>
        <provider>com.ultramain.persistence.manager.USIPersistenceProvider</provider>
        <jta-data-source>java:jboss/datasources/TechLogsGroundDS</jta-data-source>
        <!-- <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> -->
        <properties>
        <!-- Properties for Hibernate -->
        <!-- Let Hibernate know that we are using an internal JBoss DS store -->
        <!-- This should only be used for development -->
        <!-- <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" 
        /> -->
        <!-- <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory" 
        /> -->
        <property name="hibernate.transaction.jta.platform"
        value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
        <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        <property name="hibernate.show_sql" value="false" />
      
        </properties>
       </persistence-unit>
      
      
       <persistence-unit name="secondary"
        transaction-type="JTA">
        <jar-file>TechLogsCommonShared.jar</jar-file>
        <provider>com.ultramain.persistence.manager.USIPersistenceProvider</provider>
        <!-- <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> -->
        <jta-data-source>java:jboss/datasources/TechLogsGroundDS</jta-data-source>
        <properties>
        <!-- Let Hibernate know that we are using an internal JBoss DS store -->
        <!-- This should only be used for development -->
        <property name="hibernate.transaction.jta.platform"
        value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
        <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        <property name="hibernate.show_sql" value="false" />
      
        </properties>
       </persistence-unit>
      </persistence>
      

       

      Here is my DS file:

      <?xml version="1.0" encoding="UTF-8"?>
      <!-- This is an unmanaged datasource. It should be used for proofs of concept 
        or testing only. It uses H2, an in memory database that ships with JBoss 
        AS. -->
      <datasources xmlns="http://www.jboss.org/ironjacamar/schema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
       <!-- The datasource is bound into JNDI at this location. We reference this 
        in META-INF/persistence.xml -->
       <datasource jndi-name="java:jboss/datasources/TechLogsGroundDS"
        pool-name="techlogs-ground" enabled="true" use-java-context="true">
        <connection-url>jdbc:h2:mem:hibernate4-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
        </connection-url>
        <driver>h2</driver>
        <security>
        <user-name>sa</user-name>
        <password>sa</password>
        </security>
       </datasource>
      </datasources>