Announcement Announcement Module
Collapse
No announcement yet.
Spring JPA transaction management Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JPA transaction management

    hi,

    im using JPA + Spring2 on my project ServiceImpl are anotated with @Transactional, and an EntityManager annotated as the @PersistenceContext, but my problem is, is there a way to manage my transaction just like in lowgrade JDBC transaction where you can have:

    try{
    save1(Object);
    save2(Object);
    delete1(object);
    transaction commit;
    }catch(Exception e){
    transaction rollback;

    }

    the objective is to be able to rollback all transactions if ever one of the transaction fails..

    can this be done? ive tried googling for this for days but it seems i cant find a solution...

    please help..

  • #2
    Just configure your transactions...

    The save1, save2, delete1 should be in a method, the transaction is on that method.

    Code:
    public class SomeServiceImpl impl SomeService {
    
    @Transactional
    public void doSomething(Object object) {
      someDao.save1(object);
      someDao.save2(object);
      someDao.delete1(object);
    }
    
    }
    The transaction is on the doSomething...

    Comment


    • #3
      How is that different from:

      @Transactional
      public void foo() {
      save1(Object);
      save2(Object);
      delete1(object);
      }

      Comment

      Working...
      X