1 Reply Latest reply on May 5, 2009 2:39 AM by voidhawc

    Use of CMP EntityManager in POJO

      Hi,

      What I'm trying to do is construct a POJO using the EntityManager injected into a session bean, pass it back to the calling session bean and use it (and the associated EM).

      According to my reading of the persistence spec this should be fine (5.6.1). But it seems to trigger a NullPointerException within the JBoss/Hibernate code as soon as any EM method that accesses the PC is called(find specifically).

      I'm using a default JBossAS 4.2.3.GA

      Any help would be appreciated.

      Thanks, Grant

        • 1. Re: Use of CMP EntityManager in POJO

          Found what could be the problem.

          This is the code that causes the null pointer in 4.2.3.GA

          public EntityManager getNonTxEntityManager()
           {
           Map map = nonTxStack.get();
           EntityManager em = (EntityManager)map.get(this); // Null Pointer here
           if (em == null)
           {
           em = entityManagerFactory.createEntityManager();
           map.put(this, em);
           }
           return em;
           }
          


          Compared against the JPA code.

          public EntityManager getNonTxEntityManager()
           {
           Map<ManagedEntityManagerFactory, EntityManager> map = nonTxStack.get();
          
           EntityManager em = null;
           if (map != null)
           em = map.get(this);
           else
           {
           map = new HashMap<ManagedEntityManagerFactory, EntityManager>();
           nonTxStack.push(map);
           }
          
           if (em == null)
           {
           em = entityManagerFactory.createEntityManager();
           map.put(this, em);
           }
           return em;
           }
          


          As you can see there is a guard around the map reference code. However the code with a guard around it appears to from revision 75254 where as the code without a guard is from 75965 which is later.

          However the 4.2 code appears to have been copied from 4.0 (rev 58000).

          Does anyone happen to know which release this was fixed in?

          Thanks