|
From: <jue...@we...> - 2003-12-09 20:16:11
|
Matthew, =20 It's indeed a bug: I've just tried a few scenarios, and it doesn't work = with multiple transactions within one pre-bound Session. Fortunately, it = was easy enough to find and fix: HibernateTransactionManager didn't = properly reset the transaction object of a pre-bound Session, therefore = the next transaction didn't open a new Hibernate transaction because it = thought there was already an active one - thus, no flushing. =20 It works nicely for me now, for example with Petclinic. I hope the = public CVS server shows the changed HibernateTransactionManager source = file promptly. =20 Juergen =20 ________________________________ Von: Matthew E. Porter [mailto:ma...@me...] Gesendet: Di 09.12.2003 20:56 An: j=FCrgen h=F6ller [werk3AT] Betreff: Fwd: [Springframework-developer] OpenSessionInViewFilter Do you think this is a bug with Spring?=20 Cheers,=20 matthew=20 Begin forwarded message:=20 From: Matthew E. Porter <ma...@me...>=20 Date: December 9, 2003 7:35:04 AM CST=20 To: spr...@li...=20 Subject: Re: [Springframework-developer] OpenSessionInViewFilter=20 Reply-To: spr...@li...=20 Juergen:=20 FWIW: I am using the OpenSessionInViewFilter with Webwork2.=20 Anyways, when the filter is applied, flushing never happens even when = using the transactionproxy factory. If I remove the filter from the = web.xml, everything works perfectly.=20 Any guesses?=20 Cheers,=20 matthew=20 On Dec 9, 2003, at 7:03 AM, j=FCrgen h=F6ller [werk3AT] wrote:=20 Matthew,=20 TransactionProxyFactoryBean can just be used to proxy Spring-managed = Java objects: in the web case, at best a whole Controller. The view = rendering is initiated by DispatcherServlet, delegating to View.render. = There is no single entry point in form of a Spring-managed bean to catch = the whole request processing. But there is the HandlerInterceptor = facility to intercept that processing at various points.=20 It's important to stress that OpenSessionInViewInterceptor for = Spring's web MVC respectively OpenSessionInViewFilter for any web = processing still lets Spring-managed business methods perform their = transactions as usual. The interceptor/filter just pre-binds a Hibernate = Session that all transactions will use to the current thread, and which = will stay open until view rendering has been completed.=20 Your TransactionProxyFactoryBean setup should work, with or without = OpenSessionInViewFilter. Note that you need to access the "OSUserDao" = bean to get transactional behavior, not the "OSUserDaoTarget" directly. = And you need to get the method pattern in the transactionAttributes = right - in the simplest case, specify:=20 <property name=3D"transactionAttributes">=20 <props>=20 <prop key=3D"*">PROPAGATION_REQUIRED</prop>=20 </props>=20 </property>=20 That should open transactions for all methods, not just ones whose = names start with "find" etc. And don't specify "readOnly" for = transactions that should persist changes: "readOnly" will switch the = underlying Hibernate Sessions to FLUSH_NEVER. A good way is to start = with the general pattern above and go more fine-granular when you've = managed to make the general case work.=20 Juergen=20 -----Original Message-----=20 From: Matthew E. Porter [mailto:ma...@me...]=20 Sent: Tuesday, December 09, 2003 1:51 PM=20 To: j=FCrgen h=F6ller [werk3AT]=20 Subject: Re: [Springframework-developer] OpenSessionInViewFilter=20 Juergen:=20 Here is what I currently have that is not working.=20 <bean id=3D"OSUserDaoTarget"=20 = class=3D"com.metissian.security.principal.provider.osuser.configuration.O= S=20 UserManagerDAO">=20 <property name=3D"sessionFactory">=20 <ref local=3D"MetalSessionFactory"/>=20 </property>=20 </bean>=20 <bean id=3D"OSUserDao"=20 = class=3D"org.springframework.transaction.interceptor.TransactionProxyFact= o=20 ryBean">=20 <property name=3D"transactionManager">=20 <ref local=3D"MetalTransactionManager"/>=20 </property>=20 <property name=3D"target">=20 <ref local=3D"OSUserDaoTarget"/>=20 </property>=20 <property name=3D"transactionAttributes">=20 <props>=20 <prop key=3D"find*">PROPAGATION_REQUIRED,readOnly</prop>=20 <prop key=3D"delete*">PROPAGATION_REQUIRED</prop>=20 <prop key=3D"update*">PROPAGATION_REQUIRED</prop>=20 <prop key=3D"save*">PROPAGATION_REQUIRED</prop>=20 </props>=20 </property>=20 </bean>=20 For some reason, I believed that wrapping an object in a=20 TransactionProxyFactoryBean provided the transactionality you talked=20 about. Am I wrong?=20 Cheers,=20 matthew=20 On Dec 9, 2003, at 12:45 AM, j=FCrgen h=F6ller [werk3AT] wrote:=20 Matthew,=20 You should either use Spring-managed transactions (via=20 HibernateTransactionManager or JtaTransactionManager), which will=20 automatically flush a Session at transaction commit, or set=20 HibernateTemplate's/HibernateInterceptor's "flushMode" property to=20 FLUSH_EAGER (respectively "flushModeName" to "FLUSH_EAGER" in a=20 textual bean definition). This will guarantee to flush as early as=20 possible, not after view rendering: After all, a view should not=20 modify the model, so there should be no need to flush afterwards.=20 Juergen=20 ________________________________=20 Von: spr...@li... im Auftrag = von Matthew E. Porter=20 Gesendet: Di 09.12.2003 02:20=20 An: spr...@li...=20 Betreff: [Springframework-developer] OpenSessionInViewFilter=20 I am attempting to use the OpenSessionInViewFilter. According to the=20 javadoc, the session is not flush at the end of the filter. = Therefore,=20 without overriding the closeSession() method in the filter, how do I=20 get the session to flush? I am currently accessing DAOs wrapped as a=20 ProxyFactoryBean with a HibernateInterceptor.=20 Please help!=20 Cheers,=20 matthew=20 -------------------------------------------------------=20 This SF.net email is sponsored by: IBM Linux Tutorials.=20 Become an expert in LINUX or just sharpen your skills. Sign up for=20 IBM's=20 Free Linux Tutorials. Learn everything from the bash shell to sys=20 admin.=20 Click now! = http://ads.osdn.com/?ad_id=3D1278&alloc_id=3D3371&op=3Dclick=20 _______________________________________________=20 Springframework-developer mailing list=20 Spr...@li...=20 = https://lists.sourceforge.net/lists/listinfo/springframework-developer=20 -------------------------------------------------------=20 This SF.net email is sponsored by: IBM Linux Tutorials.=20 Become an expert in LINUX or just sharpen your skills. Sign up for=20 IBM's=20 Free Linux Tutorials. Learn everything from the bash shell to sys=20 admin.=20 Click now! http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick=20 _______________________________________________=20 Springframework-developer mailing list=20 Spr...@li...=20 = https://lists.sourceforge.net/lists/listinfo/springframework-developer=20 -------------------------------------------------------=20 This SF.net email is sponsored by: IBM Linux Tutorials.=20 Become an expert in LINUX or just sharpen your skills. Sign up for = IBM's=20 Free Linux Tutorials. Learn everything from the bash shell to sys = admin.=20 Click now! http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick=20 _______________________________________________=20 Springframework-developer mailing list=20 Spr...@li...=20 https://lists.sourceforge.net/lists/listinfo/springframework-developer = -------------------------------------------------------=20 This SF.net email is sponsored by: IBM Linux Tutorials.=20 Become an expert in LINUX or just sharpen your skills. Sign up for = IBM's=20 Free Linux Tutorials. Learn everything from the bash shell to sys = admin.=20 Click now! http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick=20 _______________________________________________=20 Springframework-developer mailing list=20 Spr...@li...=20 https://lists.sourceforge.net/lists/listinfo/springframework-developer=20 |