|
From: Chris R. <chr...@gm...> - 2004-07-06 20:02:00
|
On Thu, 24 Jun 2004 18:03:56 -0700, Norris, Tyson <tys...@be...> wrote: > Hi Folks - > We have been running into problems with migrating an existing CMT EJB > application to use OpenSessionInViewFilter, and here are a couple > thoughts on the subject. > > The basic problem is that when a session is created, then a transaction > is initiated and uses that session, if the transaction rolls back, how > can we still access the initial session created in the filter? > > Currently the same session is used after entering the transaction. This > is a problem for us using weblogic, since weblogic datasource become > useless after a transaction rolls back (or commits), but I think this is > also general practice for hibernate users to close the session on > rollback: > "If you rollback the transaction you should immediately close and > discard the current session to ensure that Hibernate's internal state is > consistent." > > So, what to do? Would it be desirable to build into SessionFactoryUtils > the ability to generate a new session for each new transaction? > This functionality would be very useful. In my application I want to rollback and retry the transaction if an optimistic locking failure occurs, i.e Hibernate throws a StaleObjectStateException. I have an interceptor that runs before the TransactionInterceptor that catches the OptimisticLockingFailureException and redoes the call. It needs to close the existing Session and open a new one. I wrote some code that does an TransactionSynchronizationManager.unbindResource() following be a close, an open and then a bindResource(). It appears to work but it would be nice if this was handled by SessionFactoryUtils Chris |