I'd like to propose a change to the Transaction API, for the purpose of making the standard try/catch/finally idiom a bit cleaner. What I would like is for the idiom to look like:
Session s = factory.openSession();
try {
//instantiate a new Transaction object, begin the transaction
s.beginTransaction();
// do some work
....
// commit the transaction
s.transaction().commit();
}
catch (Exception e) {
// attempt to roll back the transaction
s.transaction().attemptRollback();
throw e;
}
finally {
s.close();
}
This will require the following changes:
1. Change Session.beginTransaction() to keep a reference to the new Transaction instance the Session.
Shouldn't there be a Session.endTransaction() as well? Or does Transaction.commit() implicitly end the Transaction (in which case you'd need a callback to let the Session know)? Once you start using Transactions, do you expect users to not want to stop using them?
5. Add attemptCommit() and attemptRollback() methods to Transaction.
Rather than throwing an exception, these methods return boolean to indicate success or failure. In particular they return false if we did not successfully begin the transaction in the first place.
6. Add Transaction.getLastException() to return any exception that
was squashed.
Not sure what benefits these methods add, since I don't think I'd ever use them...
-Mark
------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel