alesj wrote:
When transaction fails it is best for you to clear or close session, since most of the times exceptions are unrecoverable.
Session is almost unaware of transaction - since you can do all the same things even if you don't use Session.beginTransaction. It is up to you if you use autoCommit (not a good usage) or commit/rollback the transaction your self.
So it is a normal behaviour that you get object from session even if you rolled back you transaction - 'parallel' independance of session and transaction.
Thanks for the reply. I guess I just didn't consider rolling back a transaction to be equivalent to an unrecoverable exception. It seems like if you had a session and wanted to execute a sequence of transactions, if one in the middle fails and is rolled back (e.g. the user cancels an operation), you should be able to continue with the rest of the transactions in the same session (i.e. continuing to use the session cache since it contains objects from the previous successful transactions).
So if my session cache is messed up after rolling back a transaction, is clearing the session sufficient, or do I need to close the session? I am wrapping the Hibernate Session in my own session object anyway, so it's easy for me to call Session.clear() in my rollback method, but I want to make sure that's ok. Does anyone know?
Thanks in advance.