0 Replies Latest reply on Jun 1, 2009 11:14 PM by Wolfgang Bergbauer

    Websphere 6.1 entityManager injection question

    Wolfgang Bergbauer Newbie

      Hi all,

      after following the excellent reference documentation to deploy the project on Websphere 6.1 I have my project up and running.
      Most of the stuff is working now, e.g. Entities/Richfaces Datatables ... but I still have troubles with the EntityManager when using with native Queries.

      In one of my beans I am injecting the EntityManager wtih:

             @PersistenceContext(type = PersistenceContextType.EXTENDED, unitName = "AudioConference")
              EntityManager em;

      Then I perform a NativeQuery:

          Query seqQuery = em.createNativeQuery("select mac_user.audio_conf_tid_seq.nextval AS TID from dual");

      This will give me a NPE.

      When I inject the entity Manager the following way, it works:

              EntityManager em;

      I have two XA datasources, one to Oracle and one to SQL 2005.
      All DB access via normal entities works fine.

      This is a snippet of my components.xml:


             <persistence:managed-persistence-context name="entityManager"
              <persistence:entity-manager-factory name="oracleManagerFactory" persistence-unit-name="AudioConference"/>      
              <persistence:managed-persistence-context name="msSqlEntityManager"
              <persistence:entity-manager-factory name="mssqlManagerFactory" persistence-unit-name="AudioConferenceMsSql"/>      
              <ui:entity-converter name="standardEntityConverter" entity-loader="#{standardEntityLoader}" />
              <ui:jpa-entity-loader name="standardEntityLoader" entity-manager="#{entityManager}" />
              <ui:entity-converter name="msSqlEntityConverter" entity-loader="#{msSqlEntityLoader}" />
              <ui:jpa-entity-loader name="msSqlEntityLoader" entity-manager="#{msSqlEntityManager}" />

      Any ideas why I am getting the NPE with injecting the entityManager via the PersistenceContext?
      Also what is the difference in the two methods?

      Thanks for your help,