All, I have a question regarding using the @Transactional annotation vs having to wrap my EntityManager.persist(entity) inside of a EntityManager.getTransaction().begin() and then EntityManager.commit();
For instance, given the following method:
Code:
public class someDao {
EntityManager em;
@Transactional(readOnly=false)
public void persist(Object entity) {
em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();
}
}
I have my test call this method and it works but... only when i wrap it inside of this em.getTransaction.begin(). I would like to know how to make it work without it, for instance, what is the purpose of the @Transactional(readOnly = false) if I have to do this for every method on my DAO? Not a huge issue, just want to know more about how it works and what is the purpose/advantage of using @Transactional over em.getTransaction().begin();
Thank you very much...