-->
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.  [ 1 post ] 
Author Message
 Post subject: em.getTransaction.begin() vs @Transactional
PostPosted: Mon Dec 27, 2010 2:27 am 
Newbie

Joined: Sun Dec 26, 2010 2:37 pm
Posts: 2
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...


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

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.