0 Replies Latest reply on Aug 4, 2005 11:07 PM by Eric Broda

    EntityManager returns null from @PersistenceContext

    Eric Broda Newbie

      I am unable to successfully create an EntityManager (returns null) using:
      - jboss 4.0.3RC1
      - operating system: Win2K
      - database: MS SQL Server 2k

      Tried to apply concepts in the EJB3 turorials, and scanned the forums for last 3 days, and tried many different configs/suggestions, but no success... any help is appreciated!

      ***

      Configuration/Code details follow:

      - the entity-manager/name configured within persistence.xml is "bgsdb" and is used as the PersistenceContext unitName (code fragment shown later); the EntityManager appears to be established based upon server.log information (again, fragment provided below)
      - standardjaws.xml and standardjbosscmp-jdbc.xml are configured to use MS SQL Server (server.log confirms that it can connect)
      - mssql-ds.xml appears configured properly (within deploy directory)

      *** persistence.xml (start) ***
      <entity-manager>
      bgsdb
      org.hibernate.ejb.HibernatePersistence
      <jta-data-source>java:/MSSQLDS</jta-data-source>




      </entity-manager>
      *** persistence.xml (end) ***


      Note: the class (code fragment below) is instantiated within a stateless session bean ("execute" method is called from this stateless session bean)
      *** Code fragment (start) ***

      package com.....

      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;

      public class CLITest {

      @PersistenceContext(unitName="bgsdb")
      EntityManager em;

      public String execute()
      throws com.brodagroup.exception.XException {

      System.out.println( "emb: CLITest started........");
      System.out.println( "emb: em: " + em );
      System.out.println( "emb: em (string): " + em.toString() );
      :
      :
      :
      :
      }

      }

      *** Code fragment (end) ***

      Upon executing the code, the EntityManager returned is null (expert from server.log is listed below)

      *** server.log - error (start) ***
      2005-08-04 22:37:25,015 INFO [STDOUT] emb: CLITest started........
      2005-08-04 22:37:25,015 INFO [STDOUT] emb: em: null
      2005-08-04 22:37:25,015 INFO [STDOUT] javax.ejb.EJBException: null; CausedByException is:
      null
      2005-08-04 22:37:25,015 INFO [STDOUT] at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:46)...........
      *** server.log - error (end) ***

      *** server.log - EntityManager appears configured (start) ***
      2005-08-04 22:28:54,180 INFO [org.jboss.ejb3.Ejb3Module] Create EntityManager with JNDI name: bgsdb
      *** server.log - EntityManager appears configured (end) ***

      *** server.log - SQL SERVER connection established (start) ***
      2005-08-04 22:28:52,037 INFO [org.hibernate.connection.DatasourceConnectionProvider] Using datasource: java:/MSSQLDS
      *** server.log - SQL SERVER connection established (end) ***