0 Replies Latest reply on Aug 6, 2007 3:42 PM by Avihai Marchiano

    Persistence context isnt propograte in the same transaction

    Avihai Marchiano Novice

      Hey,

      I work with JBoss 4.2.

      I create entity manager and use it to persist hotel.
      Than i create additional entity manager and use it to find the hotel that i saved with the first one.

      I get null (it didnt find it), unless i call to flush on the first one.

      According to the spec in JTA env the persistence context is bound to the transaction.

      Does any one know how to solve this?

      Thank you.
      p.s - dont say injection. i cant use injection.

      I wrote a stataless bean:
      @Stateless
      @Local(HotelService2.class)
      @Remote(HotelService2.class)
      public class HotelServiceBean2 implements HotelService2 {


      and in the stateless i have the following method:

      public void createEntityManagerFactory() {
      try {
      FactorySingleton.getInstance();
      EntityManagerFactory emf2 = (EntityManagerFactory) new InitialContext().lookup("java:/DemoEMF");
      EntityManager em = emf2.createEntityManager();
      Hotel hot = new Hotel("ab","");
      em.persist(hot);
      //em.flush();
      EntityManager em2 = emf2.createEntityManager();
      Hotel foundHot = em.find(Hotel.class, hot.getOrmID());
      } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }

      }



      <persistence-unit name="Demo">
      <jta-data-source>java:/InsiteDS</jta-data-source>





      </persistence-unit>