0 Replies Latest reply on Jan 15, 2008 7:19 AM by seb Raickman

    ransactionAttributeType REQUIRES_NEW ignored in stateless

    seb Raickman Newbie

      i 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" />
      </bean>
      <jee:jndi-lookup id="entityManagerBPM" jndi-name="persistence/manager1"/>
      



      My problem:

      - in the first stateless, I do:
      with the following annotation above the function:
      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
      public void saveEntity(PersistentBean bean) {
      
       if(bean.isNew())
       em.persist(bean);
       else
       em.flush();
      }
      


      - 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, means that the REQUIRES_NEW attribute is ignored.

      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.

      Thanks