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]