-->
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: handle failed saveOrUpdate with rollback
PostPosted: Fri Jun 27, 2008 1:26 pm 
Beginner
Beginner

Joined: Fri May 16, 2008 3:59 pm
Posts: 30
All,

I here you cannot rollback after committing. So I plan to use this code to rollback if my updates fail:

Code:
try{
            session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            
            session.saveOrUpdate(fa);
            
            }catch(HibernateException ex){
               ex.printStackTrace();
               log.error(ex.getMessage());
               session.getTransaction().rollback();
               
            }
            // This closes the session.
            // If you call it again, you'll get an exception
            session.getTransaction().commit();
            parsed = true;

         }


Does this look right/well?
Please give your input.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 28, 2008 5:40 am 
Beginner
Beginner

Joined: Wed Sep 21, 2005 8:18 am
Posts: 31
Well you don't need to explicity mention session.rollback because if transaction is not committed, all operations are rollback automatically on close of session.

_________________
amer sohail


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 28, 2008 12:30 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
The failed commit will trigger a rollback to all of the resources that participated in the transaction. So, to that end, you don't need any extra code to do the rollback.

Is there perhaps some higher purpose you're trying to achieve here, such as reporting the rollback to other resources, reporting or logging mechanisms?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Rollback
PostPosted: Mon Jun 30, 2008 9:06 am 
Beginner
Beginner

Joined: Fri May 16, 2008 3:59 pm
Posts: 30
I am beginning to realize what I'm trying to achieve is a batch all or none process. So maybe I'm explaining myself incorrectly.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 10:52 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
If it's a batch process, then use batch processing!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.