[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Persistence context isnt propograte in the same transaction

avihaimar do-not-reply at jboss.com
Mon Aug 6 15:42:34 EDT 2007


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> 
 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071340#4071340

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071340



More information about the jboss-user mailing list