|
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 |