|
From: Daniel M. <mi...@pa...> - 2004-06-14 03:25:40
|
James, >Does that also mean that a new Hibernate session is created if a data access occurs after the exception? (Think of an app that logs application failures to a database.) No, that is the problem--the same session continues to be used after the exception occurs. >From the Hibernate Session interface javadoc: "If the Session throws an exception, the transaction must be rolled back and the session discarded. The internal state of the Session might not be consistent with the database after the exception occurs." http://www.hibernate.org/hib_docs/api/net/sf/hibernate/Session.html >Also, is the discarding (shutting down) of a session handled by the transaction manager or some other wrapper? I'm trying to understand if the discard behavior is the same for checked or unchecked exceptions. Our apps are set up to throw checked exceptions when we think the application could recover from the failure. No, discarding is not handled by the transaction manager. The session only needs to be discarded if a HibernateException is thrown (checked). If you use Spring's HibernateDAOSupport for your DAO's, Spring catches the HibernateExceptions and wraps them in DataAccessExceptions (unchecked). >In cases where a checked exception is deemed fatal we control rollback using: TransactionInterceptor.currentTransactionStatus().setRollbackOnly(); A rollback wouldn't solve the problem because you would still be using the same (potentially damaged) session for other data accesses after the exception occurred. > The Hibernate session will always get discarded properly, even when > exceptions get thrown during view rendering. If that doesn't happen in any > case, it's a bug in either Spring's interceptor/filter implementations (or > the servlet container's handling of filters, in case of > OpenSessionInViewFilter). > > Juergen Sorry Juergen, I worded my original message wrongly. The session is always properly discarded by Spring at the end of the request. Both the filter and the interceptor versions of OpenSessionInView do this correctly. However, they cannot tell when an exception is thrown in the middle of your business logic and therefore cannot discard the session and create a new one after an exception occurs. Daniel ------------------------------------------------------- This SF.Net email is sponsored by the new InstallShield X. >From Windows to Linux, servers to mobile, InstallShield X is the one installation-authoring solution that does it all. Learn more and evaluate today! http://www.installshield.com/Dev2Dev/0504 _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |