|
From: Norris, T. <tys...@be...> - 2004-06-25 01:04:16
|
Hi Folks -=20 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?=20 I have worked around the problem temporarily by "manually" doing this. That is, I check for an existing JTA transaction, and if its their, register a new synchronization that holds a reference to the session opened with the OpenSessionInViewFilter, and the TransactionSynchronizationManager's session is unbound. When the transaction completes, TransactionSynchronizationManager session is re-bound, and non-transactional data access can proceed after the commit or rollback. This of course presents a potential problem of loading the same data in multiple sessions, but this may be negligible for many cases. Is this something worth adding as an additional parameter to SessionFactoryUtils.getSession()? When specified (true), if an existing SessionHolder is found, if not already synchronized with a transaction, it would be replaced with a new session, then restored after the transaction completes. Let me know what you think. Or if there is a better alternative, I'm all ears :) Thanks tyson =20 |
|
From: James C. <jim...@do...> - 2004-06-25 13:36:46
|
I was wondering (out loud) if Hibernate's session.clear() couldn't be used to "reinitialize" its session for continuing work after a rollback or exception? I suppose if a rollback invalidates the datasource from further activity on certain platforms that it wouldn't matter if Hibernate could recover on its own. For many that currently need this feature, I suppose they are architecting their application to use SAO methods as their transactional units. If a rollback occurs, it occurs only in the scope of the SAO method call. They would also have to "exercise" their business objects in order to load lazy collections in the SAO instead of the web tier. I don't mean to minimize the goal you are trying to achieve, but what are some use cases where a developer needs to reuse a session after a rollback? Is this in relation to nested transactions? > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...] On Behalf > Of Norris, Tyson > Sent: Thursday, June 24, 2004 9:04 PM > To: spr...@li... > Subject: [Springframework-developer] OpenSessionInViewFilter ideas > > 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? > > I have worked around the problem temporarily by "manually" doing this. > That is, I check for an existing JTA transaction, and if its their, > register a new synchronization that holds a reference to the session > opened with the OpenSessionInViewFilter, and the > TransactionSynchronizationManager's session is unbound. When the > transaction completes, TransactionSynchronizationManager session is > re-bound, and non-transactional data access can proceed after the commit > or rollback. > > This of course presents a potential problem of loading the same data in > multiple sessions, but this may be negligible for many cases. > > Is this something worth adding as an additional parameter to > SessionFactoryUtils.getSession()? When specified (true), if an existing > SessionHolder is found, if not already synchronized with a transaction, > it would be replaced with a new session, then restored after the > transaction completes. > > Let me know what you think. Or if there is a better alternative, I'm all > ears :) > > Thanks > tyson > > > > > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > digital self defense, top technical experts, no vendor pitches, > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
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 |