0 Replies Latest reply on Jan 11, 2008 7:57 AM by seb Raickman

    PersistenceContext shared between Ejbs' (CMB)

    seb Raickman Newbie

      Hi all,

      I have an ear application running on JBoss 4.2.1 GA that contains 2 EJB Stateless jar's. I have only one persistence unit define in the persistence.xml of only one of the jar/META-INF.
      All is container-managed, so JTA is used and I don't need to manage transaction. The isolation level of my DB is read_commited.

      In the first EJB jar, the EntityManager is injected (@PersistenceContext).
      In the second one, the Entity manager is retrieved by Spring and JNDI (but should be the same as the one used in the first EJB) as follow:

      <bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
       <property name="entityManager" ref="entityManagerBPM" />
      <jee:jndi-lookup id="entityManagerBPM" jndi-name="persistence/manager1"/>

      My problem:

      - in the first stateless, I do em.persist(bean);
      - in the second one (after the persist) I do a em.find(bean.getClass(), bean.getId());

      Sometimes the find cannot retrieve the bean. I guess that the transaction of the persist caller has not been commited.

      If you had any idea on how to use the really same instance of the EntityManager between stateless bean (CMB) please let me know about it.