-->
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.  [ 2 posts ] 
Author Message
 Post subject: Transactions over database ops AND normal POJO methods
PostPosted: Wed Jun 30, 2004 3:44 am 
Newbie

Joined: Wed Jun 30, 2004 3:39 am
Posts: 1
I have a small method that looks like this:

Account account = (Account)accountDAO.findByUserID(userID);
account.depositAmount(amount);
accountDAO.store(account);

The .store() method may sometimes throw MyIOException (when database access fails), and in these cases I would like to rollback this whole code snippet ie I would like to undo my call to the depositAmount() method. Can I do this somehow using Hibernate and/or Spring?

If this is not doable, is it safe to clone the account object, call the depositAmount() on the cloned object and then try to save that? In this case if the .store() method fails, I could just throw-away the reference to the cloned object and it would be garabage collected, no?


Sincerly,
Martin Olsson


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 4:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Hibernate has full support for transactions so if the operation in question is wrapped in a transaction (as it should be) then the answer is yes. Cloning the POJO can be OK - I would return the clone on error rather than update it as it will be obvious what your doing when reading the code.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.