7 Replies Latest reply on Aug 9, 2016 7:16 AM by Tavleen Oberoi

    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