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
|