-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to rollback?
PostPosted: Thu Nov 11, 2004 2:12 pm 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
Hibernate version:2.1.6


Code between sessionFactory.openSession() and session.close():
public void savePostingIdentification(final PostingIdentification pid){
this.getHibernateTemplate().save(pid);
}

public void saveClassified(final Classified classified){
this.getHibernateTemplate().save(classified);
}


Name and version of the database you are using:MySQL 4.1.7


Hi guys,

I got two function, for which when user click the submit button, I will execute savePostingIdentification then saveClassified. But if sometime saveClassified fail to save, I need to rollback the saved PostingIdentification. How can I do that? Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 11, 2004 2:21 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
wrap it within a transaction.

something like this:
Code:
    Session hibernateSession = null;
    Transaction transaction = null;
    try
    {
      if (orderType != null)
      {
        hibernateSession = HibernateManager.currentSession();
        transaction = hibernateSession.beginTransaction();
        hibernateSession.saveOrUpdate(orderType);
        transaction.commit();
        saved = true;
      }
    }
    catch (HibernateException e)
    {
      try
      {
        transaction.rollback();
      }
      catch (Exception ex)
      {
        logger.warn("Exception encountered rolling back transaction due to HibernateException in " + sMethodName + Utilities.getStackTrace(ex));
      }

      logger.warn("Hibernate Exception in " + sMethodName + Utilities.getStackTrace(e));
    }
    finally
    {
       // Blah Blah
     }



Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 11, 2004 10:02 pm 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
Is there anyway that we can configure in applicationContext.xml?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 12, 2004 3:11 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
well, you could look at Spring to do your transaction management.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 12, 2004 3:31 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you can also get hibernateutil & hibernatefilter, easy to use and do the work (download caveatemptor)
http://caveatemptor.hibernate.org/

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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

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.