6 Replies Latest reply: Dec 2, 2013 1:40 PM by mauricio aiello RSS

    NPE when calling createEntityManager

    David Robison Novice

      I am typing to create an entity manager programatically like:

       

      EntityManagerFactory emf = Persistence.createEntityManagerFactory("VATVD-DS");

      EntityManager em = emf.createEntityManager();

       

      When I do I get a NullPointerException:

       

      java.lang.NullPointerException

           at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:73)

           at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:115)

          at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149)

          at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1204)

           at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:175)

           at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:90)

           at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:111)

       

      My persistence.xml is

       

      <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">

        <persistence-unit name="VATVD-DS">

          <jta-data-source>java:jboss/datasources/VATVD-DS</jta-data-source>

          <class>com.orci.VATVD.db.hibernate.DGNodeStatus</class>   

          <class>com.orci.VATVD.db.hibernate.DGNodeStatusLog</class>   

          <properties>

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

              <property name="hibernate.showSql" value="false"/>

          </properties>

        </persistence-unit>

      </persistence>

       

      Any idea what I am doing wrong? I am using JBoss 7.1.0.CR1b

      I've read some threads on the Internet but have not found anyway to do this as a jta-data-source. When I use non-jta-data-source then I have trouble actually writeing data to the database.

      Any thoughts?

      David

        • 1. Re: NPE when calling createEntityManager
          David Robison Novice

          I had to add the following to my persistence.xml file

           

          <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />

          • 2. Re: NPE when calling createEntityManager
            David Robison Novice

            I had to add the following to my persistence.xml file

             

            <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />

            • 3. Re: NPE when calling createEntityManager
              Rok Koncina Newbie

              Thank you for this post - it helped me solve my similar problem.

              I was trying to deploy the application on Weblogic 12g with Hibernate as data source provider:

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

               

              I was getting the following error while injecting persistence context into an EJB:

              Caused By: java.lang.NullPointerException

                        at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:73)

                        at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:115)

                        at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149)

                        at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1220)

                        at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:178)

                        Truncated. see log file for complete stacktrace

               

              The sollution was to add

              <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform"/>

              into persistence.xml.

              • 4. Re: NPE when calling createEntityManager
                Mrinal Thigale Newbie

                Thanks a lot ! This worked like a charm !

                • 5. Re: NPE when calling createEntityManager
                  RĂ¼diger zu Dohna Newbie

                  This worked for me also. Thanks!

                   

                  But: Is this a bug in Hibernate? Is there an bug report? Can I keep this outside of my app?

                   

                  And you should mark this question as answered.

                  • 6. Re: NPE when calling createEntityManager
                    mauricio aiello Newbie

                    The issue with OpenJPA.

                     

                    I added this line on my persistence.xml and works.

                     

                    <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />

                     

                    Do I need to report as a bg of Jboss As 7.1.1 ???

                     

                    Thanks David for this workaround.