From the Hibernate manual:
Quote:
If the Session throws an exception (including any SQLException), you should immediately rollback the transaction, call Session.close() and discard the Session instance. Certain methods of Session will not leave the session in a consistent state.
Is this the most definitive statement that the Hibernate team can make regarding exception handling? Is it
always necessary to discard the Session on
any exception?
I was told in
another thread that I don't need to discard the Session after an ObjectNotFoundException.
I understand well why a Session needs to be discarded when a transaction commit fails or there's a SqlException or JdbcException. But I don't understand why errors stemming from lock failures or stale data should require the Session to be discarded, especially when the operation was
read-only (and did not trigger a Session flush).
In short: which methods/exception leave the Session in an invalid state and require it to be discarded?
- ObjectNotFoundException
- ObjectDeletedException
- StaleObjectStateException
- TransientDataException
p.s. I glanced through my electronic preview of Hibernate in Action, and did not see where this was addressed.