Announcement Announcement Module
Collapse
No announcement yet.
How to Transaction by using HibernateTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Transaction by using HibernateTemplate

    I use getHibernateTemplate() method to get HibernateTemplate Object,then I use delete(Object entity) method to delete some database record,like follows:
    getHibernateTemplate().delete(entity1);
    getHibernateTemplate().delete(entity2);

    My question is I want to know if HibernateTemplate support commit and rollback? Because I want to realize following function:

    Code:
    getHibernateTemplate().setCommit("false"); 
    try{
       getHibernateTemplate().delete(entity1);  
       getHibernateTemplate().delete(entity2);
       getHibernateTemplate().commit();
    }
    catch(){
       getHibernateTemplate().rollback();
    }
    How to realize above function?
    Thanks

  • #2
    You can use the Hibernate API directly and don't need to use the HibernateTemplate.

    Joerg

    Comment


    • #3
      As Jörg said, you don't have to use HibernateTemplate. Either way however it sounds like you need to have a look at transactions.
      http://www.springframework.org/docs/...decl-explained

      Comment

      Working...
      X