-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Persistence context isnt propograte in the same transaction
PostPosted: Mon Aug 06, 2007 1:33 pm 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
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.

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

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


and in the stateless i have the following method:

Code:
   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();
      }

   }


Code:
<persistence>
  <persistence-unit name="Demo">
    <jta-data-source>java:/InsiteDS</jta-data-source>
    <properties>
            <property name="hibernate.transaction.factory_class" value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory"/>
      <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
      <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultComponentSafeNamingStrategy" />
    </properties>
  </persistence-unit>
</persistence>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 2:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Like you did, you need to explicitly flush. Those are 2 different EMs.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: What about getCurrentEntityManager?
PostPosted: Wed Aug 08, 2007 9:16 am 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
I saw that some one rewrite the class for this.

Is it correct -
We have here two entity manager which share the same JDBC connection and the same transaction, but not share the same persistence context.


Top
 Profile  
 
 Post subject: What do you think about this solution?
PostPosted: Wed Aug 08, 2007 11:28 am 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
I create the factory like this:

Code:
         EntityManagerFactory programmaticEmf =
             Persistence.createEntityManagerFactory("Demo",configOverrides);
         managedEntityManagerFactory = new ManagedEntityManagerFactory(programmaticEmf,"");


Than in order to get the entity manager -
Code:
em = entityManagerFactory.getTransactionScopedEntityManager();


What suppose to be in the kernelName field in the constructor of ManagedEntityManagerFactory?

Thank you


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.