About Question enthuware.oce-jpad.v6.2.518 :
Posted: Sun Sep 02, 2012 8:48 am
Isn't a required here ? otherwise the persist will do nothing
Code: Select all
em.joinTransaction()
Java Certification Resources and Java Discussion Forum
http://enthuware.com/forum/
Code: Select all
em.joinTransaction()
Code: Select all
EntityManagerFactory emf = Persistence.createEntityManagerFactory("aPU");
EntityManager em = emf.createEntityManager();
//This persistence context is created when the em is created.
// It is created outside the new transaction
//The new transaction is created and begin after the em is created.
em.getTransaction().begin();
Code: Select all
//In a stateful bean
@PersistenceContext(unitName="aPU")
EntityManagerFactory emf;
EntityManager em;
public void init(){
emf = Persistence.createEntityManagerFactory("aPU");
em = emf.createEntityManager();
}
public void add(....){
em.joinTranscation();
//anEntity is an entity
em.persist(anEntity);
}