|
From: Norris, T. <tys...@be...> - 2004-06-26 23:33:21
|
Hey folks - any other thoughts on this? Thanks! tyson -----Original Message----- From: Norris, Tyson=20 Sent: Friday, June 25, 2004 8:21 AM To: spr...@li... Subject: RE: [Springframework-developer] OpenSessionInViewFilter ideas The typical use case for accessing a session after rollback is accessing read-only data which should be available regardless of any transaction success or failure.=20 Specifically, we have various data that is used to customize the navigation framework of our webapp. I won't argue that its not efficient to look it up with each request, but there is nothing technically wrong with it. Currently, the session opened in OpenSessionInViewFilter will be used within the transaction, which causes problems for rollbacks (and even commits for some unfortunate enough to use weblogic :). The problem being that after rollback or commit, the navigation data access fails because the connection is now defunct. Yes, our app is currently architected to use certain methods as transactional units, with all of them using "REQUIRES" propagation (some EJB, some spring/hibernate). We could potentially avoid this problem by using "REQUIRES_NEW", and have the filter create a new tx (instead of just open a session) which will affect the datasource behavior in regards to the transaction, but this breaks the potential interaction of many of these methods - there should only be 1 transaction per request. In this way, you could say it's a "nested tx problem", but only in that we can't use "true nested tx", and requires_new is not useable for us either. Session.clear() would help in the case where the lazy-loading-data is accessed *after* any transactional behavior, but NOT in the case where data is accessed *before* the transaction. I would rather not force specific ordering with regards to transactional methods and lazy-loading-dependent methods. Let me know what you think Tyson -----Original Message----- From: James Cook [mailto:jim...@do...]=20 Sent: Friday, June 25, 2004 6:37 AM To: spr...@li... Subject: RE: [Springframework-developer] OpenSessionInViewFilter ideas 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 >=20 > 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. >=20 > 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? >=20 > 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." >=20 > 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. >=20 > This of course presents a potential problem of loading the same data in > multiple sessions, but this may be negligible for many cases. >=20 > 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. >=20 > Let me know what you think. Or if there is a better alternative, I'm all > ears :) >=20 > Thanks > tyson >=20 >=20 >=20 >=20 > ------------------------------------------------------- > 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 ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 -=20 digital self defense, top technical experts, no vendor pitches,=20 unmatched networking opportunities. Visit www.blackhat.com _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 -=20 digital self defense, top technical experts, no vendor pitches,=20 unmatched networking opportunities. Visit www.blackhat.com _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |