|
From: <jue...@we...> - 2003-12-09 06:51:16
|
Matthew, =20 You should either use Spring-managed transactions (via = HibernateTransactionManager or JtaTransactionManager), which will = automatically flush a Session at transaction commit, or set = HibernateTemplate's/HibernateInterceptor's "flushMode" property to = FLUSH_EAGER (respectively "flushModeName" to "FLUSH_EAGER" in a textual = bean definition). This will guarantee to flush as early as possible, not = after view rendering: After all, a view should not modify the model, so = there should be no need to flush afterwards. =20 Juergen =20 ________________________________ Von: spr...@li... im Auftrag = von Matthew E. Porter Gesendet: Di 09.12.2003 02:20 An: spr...@li... Betreff: [Springframework-developer] OpenSessionInViewFilter I am attempting to use the OpenSessionInViewFilter. According to the javadoc, the session is not flush at the end of the filter. Therefore, without overriding the closeSession() method in the filter, how do I get the session to flush? I am currently accessing DAOs wrapped as a ProxyFactoryBean with a HibernateInterceptor. Please help! Cheers, matthew ------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for = IBM's Free Linux Tutorials. Learn everything from the bash shell to sys = admin. Click now! http://ads.osdn.com/?ad_id=3D1278&alloc_id=3D3371&op=3Dclick _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
From: <jue...@we...> - 2003-12-09 13:04:39
|
Matthew,
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.
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.
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:
<property name=3D"transactionAttributes">
<props>
<prop key=3D"*">PROPAGATION_REQUIRED</prop>
</props>
</property>
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.
Juergen
-----Original Message-----
From: Matthew E. Porter [mailto:ma...@me...]
Sent: Tuesday, December 09, 2003 1:51 PM
To: j=FCrgen h=F6ller [werk3AT]
Subject: Re: [Springframework-developer] OpenSessionInViewFilter
Juergen:
Here is what I currently have that is not working.
<bean id=3D"OSUserDaoTarget" =20
class=3D"com.metissian.security.principal.provider.osuser.configuration.O=
S=20
UserManagerDAO">
<property name=3D"sessionFactory">
<ref local=3D"MetalSessionFactory"/>
</property>
</bean>
<bean id=3D"OSUserDao" =20
class=3D"org.springframework.transaction.interceptor.TransactionProxyFact=
o=20
ryBean">
<property name=3D"transactionManager">
<ref local=3D"MetalTransactionManager"/>
</property>
<property name=3D"target">
<ref local=3D"OSUserDaoTarget"/>
</property>
<property name=3D"transactionAttributes">
<props>
<prop =
key=3D"find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key=3D"delete*">PROPAGATION_REQUIRED</prop>
<prop key=3D"update*">PROPAGATION_REQUIRED</prop>
<prop key=3D"save*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
For some reason, I believed that wrapping an object in a =20
TransactionProxyFactoryBean provided the transactionality you talked =20
about. Am I wrong?
Cheers,
matthew
On Dec 9, 2003, at 12:45 AM, j=FCrgen h=F6ller [werk3AT] wrote:
> Matthew,
>
> 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.
>
> Juergen
>
>
> ________________________________
>
> Von: spr...@li... im Auftrag =
> von Matthew E. Porter
> Gesendet: Di 09.12.2003 02:20
> An: spr...@li...
> Betreff: [Springframework-developer] OpenSessionInViewFilter
>
>
>
> I am attempting to use the OpenSessionInViewFilter. According to the
> javadoc, the session is not flush at the end of the filter. =
Therefore,
> without overriding the closeSession() method in the filter, how do I
> get the session to flush? I am currently accessing DAOs wrapped as a
> ProxyFactoryBean with a HibernateInterceptor.
>
> Please help!
>
>
> Cheers,
> matthew
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for =20
> IBM's
> Free Linux Tutorials. Learn everything from the bash shell to sys =20
> admin.
> Click now! =
http://ads.osdn.com/?ad_id=3D1278&alloc_id=3D3371&op=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for =20
> IBM's
> Free Linux Tutorials. Learn everything from the bash shell to sys =20
> admin.
> Click now! http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: Matthew E. P. <ma...@me...> - 2003-12-09 13:35:12
|
Juergen: FWIW: I am using the OpenSessionInViewFilter with Webwork2. Anyways, when the filter is applied, flushing never happens even when = =20 using the transactionproxy factory. If I remove the filter from the =20 web.xml, everything works perfectly. Any guesses? Cheers, matthew On Dec 9, 2003, at 7:03 AM, j=FCrgen h=F6ller [werk3AT] wrote: > Matthew, > > TransactionProxyFactoryBean can just be used to proxy Spring-managed =20= > Java objects: in the web case, at best a whole Controller. The view =20= > rendering is initiated by DispatcherServlet, delegating to =20 > View.render. There is no single entry point in form of a =20 > Spring-managed bean to catch the whole request processing. But there =20= > is the HandlerInterceptor facility to intercept that processing at =20 > various points. > > It's important to stress that OpenSessionInViewInterceptor for =20 > Spring's web MVC respectively OpenSessionInViewFilter for any web =20 > processing still lets Spring-managed business methods perform their =20= > transactions as usual. The interceptor/filter just pre-binds a =20 > Hibernate Session that all transactions will use to the current =20 > thread, and which will stay open until view rendering has been =20 > completed. > > Your TransactionProxyFactoryBean setup should work, with or without =20= > OpenSessionInViewFilter. Note that you need to access the "OSUserDao" =20= > bean to get transactional behavior, not the "OSUserDaoTarget" =20 > directly. And you need to get the method pattern in the =20 > transactionAttributes right - in the simplest case, specify: > > <property name=3D"transactionAttributes"> > <props> > <prop key=3D"*">PROPAGATION_REQUIRED</prop> > </props> > </property> > > That should open transactions for all methods, not just ones whose =20 > names start with "find" etc. And don't specify "readOnly" for =20 > transactions that should persist changes: "readOnly" will switch the =20= > underlying Hibernate Sessions to FLUSH_NEVER. A good way is to start =20= > with the general pattern above and go more fine-granular when you've =20= > managed to make the general case work. > > Juergen > > > -----Original Message----- > From: Matthew E. Porter [mailto:ma...@me...] > Sent: Tuesday, December 09, 2003 1:51 PM > To: j=FCrgen h=F6ller [werk3AT] > Subject: Re: [Springframework-developer] OpenSessionInViewFilter > > > Juergen: > Here is what I currently have that is not working. > > <bean id=3D"OSUserDaoTarget" > = class=3D"com.metissian.security.principal.provider.osuser.configuration.O=20= > S > UserManagerDAO"> > <property name=3D"sessionFactory"> > <ref local=3D"MetalSessionFactory"/> > </property> > </bean> > > <bean id=3D"OSUserDao" > = class=3D"org.springframework.transaction.interceptor.TransactionProxyFact=20= > o > ryBean"> > <property name=3D"transactionManager"> > <ref local=3D"MetalTransactionManager"/> > </property> > <property name=3D"target"> > <ref local=3D"OSUserDaoTarget"/> > </property> > <property name=3D"transactionAttributes"> > <props> > <prop = key=3D"find*">PROPAGATION_REQUIRED,readOnly</prop> > <prop key=3D"delete*">PROPAGATION_REQUIRED</prop> > <prop key=3D"update*">PROPAGATION_REQUIRED</prop> > <prop key=3D"save*">PROPAGATION_REQUIRED</prop> > </props> > </property> > </bean> > > > For some reason, I believed that wrapping an object in a > TransactionProxyFactoryBean provided the transactionality you talked > about. Am I wrong? > > > Cheers, > matthew > > On Dec 9, 2003, at 12:45 AM, j=FCrgen h=F6ller [werk3AT] wrote: > >> Matthew, >> >> You should either use Spring-managed transactions (via >> HibernateTransactionManager or JtaTransactionManager), which will >> automatically flush a Session at transaction commit, or set >> HibernateTemplate's/HibernateInterceptor's "flushMode" property to >> FLUSH_EAGER (respectively "flushModeName" to "FLUSH_EAGER" in a >> textual bean definition). This will guarantee to flush as early as >> possible, not after view rendering: After all, a view should not >> modify the model, so there should be no need to flush afterwards. >> >> Juergen >> >> >> ________________________________ >> >> Von: spr...@li... im Auftrag >> von Matthew E. Porter >> Gesendet: Di 09.12.2003 02:20 >> An: spr...@li... >> Betreff: [Springframework-developer] OpenSessionInViewFilter >> >> >> >> I am attempting to use the OpenSessionInViewFilter. According to the >> javadoc, the session is not flush at the end of the filter. =20 >> Therefore, >> without overriding the closeSession() method in the filter, how do I >> get the session to flush? I am currently accessing DAOs wrapped as a >> ProxyFactoryBean with a HibernateInterceptor. >> >> Please help! >> >> >> Cheers, >> matthew >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: IBM Linux Tutorials. >> Become an expert in LINUX or just sharpen your skills. Sign up for >> IBM's >> Free Linux Tutorials. Learn everything from the bash shell to sys >> admin. >> Click now! http://ads.osdn.com/?ad_id=3D1278&alloc_id=3D3371&op=3Dclick= >> _______________________________________________ >> Springframework-developer mailing list >> Spr...@li... >> = https://lists.sourceforge.net/lists/listinfo/springframework-developer >> >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: IBM Linux Tutorials. >> Become an expert in LINUX or just sharpen your skills. Sign up for >> IBM's >> Free Linux Tutorials. Learn everything from the bash shell to sys >> admin. >> Click now! http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick >> _______________________________________________ >> Springframework-developer mailing list >> Spr...@li... >> = https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux Tutorials. > Become an expert in LINUX or just sharpen your skills. Sign up for =20= > IBM's > Free Linux Tutorials. Learn everything from the bash shell to sys =20 > admin. > Click now! http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
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 |
|
From: <jue...@we...> - 2003-12-09 20:27:51
|
BTW, that didn't affect normal HibernateTransactionManager transactions =
at all, just ones with pre-bound Session - for which =
OpenSessionInViewFilter is the first practical use case. And thanks for =
early-adopting the filter! :-)
=20
Mike, please update from CVS too if you're trying the =
OpenSessionInViewFilter!
=20
Juergen
=20
________________________________
Von: spr...@li... im Auftrag =
von j=FCrgen h=F6ller [werk3AT]
Gesendet: Di 09.12.2003 21:14
An: Matthew E. Porter
Cc: spr...@li...
Betreff: Re: [Springframework-developer] OpenSessionInViewFilter
Matthew,
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.
It works nicely for me now, for example with Petclinic. I hope the =
public CVS server shows the changed HibernateTransactionManager source =
file promptly.
Juergen
________________________________
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?
Cheers,
matthew
Begin forwarded message:
From: Matthew E. Porter <ma...@me...>
Date: December 9, 2003 7:35:04 AM CST
To: spr...@li...
Subject: Re: [Springframework-developer] OpenSessionInViewFilter
Reply-To: spr...@li...
Juergen:
FWIW: I am using the OpenSessionInViewFilter with Webwork2.
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.
Any guesses?
Cheers,
matthew
On Dec 9, 2003, at 7:03 AM, j=FCrgen h=F6ller [werk3AT] wrote:
Matthew,
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.
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.
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:
<property name=3D"transactionAttributes">
<props>
<prop key=3D"*">PROPAGATION_REQUIRED</prop>
</props>
</property>
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.
Juergen
-----Original Message-----
From: Matthew E. Porter [mailto:ma...@me...]
Sent: Tuesday, December 09, 2003 1:51 PM
To: j=FCrgen h=F6ller [werk3AT]
Subject: Re: [Springframework-developer] =
OpenSessionInViewFilter
Juergen:
Here is what I currently have that is not working.
<bean id=3D"OSUserDaoTarget"
=
class=3D"com.metissian.security.principal.provider.osuser.configuration.O=
S
UserManagerDAO">
<property name=3D"sessionFactory">
<ref local=3D"MetalSessionFactory"/>
</property>
</bean>
<bean id=3D"OSUserDao"
=
class=3D"org.springframework.transaction.interceptor.TransactionProxyFact=
o
ryBean">
<property name=3D"transactionManager">
<ref local=3D"MetalTransactionManager"/>
</property>
<property name=3D"target">
<ref local=3D"OSUserDaoTarget"/>
</property>
<property name=3D"transactionAttributes">
<props>
<prop key=3D"find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key=3D"delete*">PROPAGATION_REQUIRED</prop>
<prop key=3D"update*">PROPAGATION_REQUIRED</prop>
<prop key=3D"save*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
For some reason, I believed that wrapping an object in a
TransactionProxyFactoryBean provided the =
transactionality you talked
about. Am I wrong?
Cheers,
matthew
On Dec 9, 2003, at 12:45 AM, j=FCrgen h=F6ller [werk3AT] =
wrote:
Matthew,
You should either use Spring-managed =
transactions (via
HibernateTransactionManager or =
JtaTransactionManager), which will
automatically flush a Session at transaction =
commit, or set
HibernateTemplate's/HibernateInterceptor's =
"flushMode" property to
FLUSH_EAGER (respectively "flushModeName" to =
"FLUSH_EAGER" in a
textual bean definition). This will guarantee to =
flush as early as
possible, not after view rendering: After all, a =
view should not
modify the model, so there should be no need to =
flush afterwards.
Juergen
________________________________
Von: =
spr...@li... im Auftrag
von Matthew E. Porter
Gesendet: Di 09.12.2003 02:20
An: =
spr...@li...
Betreff: [Springframework-developer] =
OpenSessionInViewFilter
I am attempting to use the =
OpenSessionInViewFilter. According to the
javadoc, the session is not flush at the end of =
the filter. Therefore,
without overriding the closeSession() method in =
the filter, how do I
get the session to flush? I am currently =
accessing DAOs wrapped as a
ProxyFactoryBean with a HibernateInterceptor.
Please help!
Cheers,
matthew
=
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux =
Tutorials.
Become an expert in LINUX or just sharpen your =
skills. Sign up for
IBM's
Free Linux Tutorials. Learn everything from the =
bash shell to sys
admin.
Click now! =
http://ads.osdn.com/?ad_id=3D1278&alloc_id=3D3371&op=3Dclick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
=
https://lists.sourceforge.net/lists/listinfo/springframework-developer
=
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux =
Tutorials.
Become an expert in LINUX or just sharpen your =
skills. Sign up for
IBM's
Free Linux Tutorials. Learn everything from the =
bash shell to sys
admin.
Click now! =
http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
=
https://lists.sourceforge.net/lists/listinfo/springframework-developer
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. =
Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash =
shell to sys admin.
Click now! =
http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
=
https://lists.sourceforge.net/lists/listinfo/springframework-developer
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up =
for IBM's
Free Linux Tutorials. Learn everything from the bash shell to =
sys admin.
Click now! =
http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
=
https://lists.sourceforge.net/lists/listinfo/springframework-developer
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for =
IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys =
admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: Matthew E. P. <ma...@me...> - 2003-12-09 20:34:44
|
You are welcome. FWIW: The bruise from banging my head against this =20= is healing nicely. Thanks for fixing it. Now, only if cvs at =20 sourceforge would ever work.... Cheers, matthew On Dec 9, 2003, at 2:22 PM, j=FCrgen h=F6ller [werk3AT] wrote: > BTW, that didn't affect normal HibernateTransactionManager =20 > transactions at all, just ones with pre-bound Session - for which =20 > OpenSessionInViewFilter is the first practical use case. And thanks =20= > for early-adopting the filter! :-) > > Mike, please update from CVS too if you're trying the =20 > OpenSessionInViewFilter! > > Juergen > > > ________________________________ > > Von: spr...@li... im Auftrag =20= > von j=FCrgen h=F6ller [werk3AT] > Gesendet: Di 09.12.2003 21:14 > An: Matthew E. Porter > Cc: spr...@li... > Betreff: Re: [Springframework-developer] OpenSessionInViewFilter > > > > Matthew, > > It's indeed a bug: I've just tried a few scenarios, and it doesn't =20 > work with multiple transactions within one pre-bound Session. =20 > Fortunately, it was easy enough to find and fix: =20 > HibernateTransactionManager didn't properly reset the transaction =20 > object of a pre-bound Session, therefore the next transaction didn't =20= > open a new Hibernate transaction because it thought there was already =20= > an active one - thus, no flushing. > > It works nicely for me now, for example with Petclinic. I hope the =20 > public CVS server shows the changed HibernateTransactionManager source = =20 > file promptly. > > Juergen > > > ________________________________ > > 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? > > > Cheers, > matthew > > Begin forwarded message: > > > From: Matthew E. Porter <ma...@me...> > Date: December 9, 2003 7:35:04 AM CST > To: spr...@li... > Subject: Re: [Springframework-developer] =20 > OpenSessionInViewFilter > Reply-To: spr...@li... > > Juergen: > FWIW: I am using the OpenSessionInViewFilter with Webwork2. > > Anyways, when the filter is applied, flushing never happens =20= > even when using the transactionproxy factory. If I remove the filter =20= > from the web.xml, everything works perfectly. > > Any guesses? > > > Cheers, > matthew > > On Dec 9, 2003, at 7:03 AM, j=FCrgen h=F6ller [werk3AT] wrote: > > > Matthew, > > TransactionProxyFactoryBean can just be used to proxy =20= > Spring-managed Java objects: in the web case, at best a whole =20 > Controller. The view rendering is initiated by DispatcherServlet, =20 > delegating to View.render. There is no single entry point in form of a = =20 > Spring-managed bean to catch the whole request processing. But there =20= > is the HandlerInterceptor facility to intercept that processing at =20 > various points. > > It's important to stress that =20 > OpenSessionInViewInterceptor for Spring's web MVC respectively =20 > OpenSessionInViewFilter for any web processing still lets =20 > Spring-managed business methods perform their transactions as usual. =20= > The interceptor/filter just pre-binds a Hibernate Session that all =20 > transactions will use to the current thread, and which will stay open =20= > until view rendering has been completed. > > Your TransactionProxyFactoryBean setup should work, =20= > with or without OpenSessionInViewFilter. Note that you need to access =20= > the "OSUserDao" bean to get transactional behavior, not the =20 > "OSUserDaoTarget" directly. And you need to get the method pattern in =20= > the transactionAttributes right - in the simplest case, specify: > > <property name=3D"transactionAttributes"> > <props> > <prop key=3D"*">PROPAGATION_REQUIRED</prop> > </props> > </property> > > That should open transactions for all methods, not =20 > just ones whose names start with "find" etc. And don't specify =20 > "readOnly" for transactions that should persist changes: "readOnly" =20= > will switch the underlying Hibernate Sessions to FLUSH_NEVER. A good =20= > way is to start with the general pattern above and go more =20 > fine-granular when you've managed to make the general case work. > > Juergen > > > -----Original Message----- > From: Matthew E. Porter [mailto:ma...@me...] > Sent: Tuesday, December 09, 2003 1:51 PM > To: j=FCrgen h=F6ller [werk3AT] > Subject: Re: [Springframework-developer] =20 > OpenSessionInViewFilter > > > Juergen: > Here is what I currently have that is not working. > > <bean id=3D"OSUserDaoTarget" > =20 > = class=3D"com.metissian.security.principal.provider.osuser.configuration.O=20= > S > UserManagerDAO"> > <property name=3D"sessionFactory"> > <ref local=3D"MetalSessionFactory"/> > </property> > </bean> > > <bean id=3D"OSUserDao" > =20 > = class=3D"org.springframework.transaction.interceptor.TransactionProxyFact=20= > o > ryBean"> > <property name=3D"transactionManager"> > <ref local=3D"MetalTransactionManager"/> > </property> > <property name=3D"target"> > <ref local=3D"OSUserDaoTarget"/> > </property> > <property name=3D"transactionAttributes"> > <props> > <prop key=3D"find*">PROPAGATION_REQUIRED,readOnly</prop>= > <prop key=3D"delete*">PROPAGATION_REQUIRED</prop> > <prop key=3D"update*">PROPAGATION_REQUIRED</prop> > <prop key=3D"save*">PROPAGATION_REQUIRED</prop> > </props> > </property> > </bean> > > > For some reason, I believed that wrapping an object in = =20 > a > TransactionProxyFactoryBean provided the =20 > transactionality you talked > about. Am I wrong? > > > Cheers, > matthew > > On Dec 9, 2003, at 12:45 AM, j=FCrgen h=F6ller = [werk3AT] =20 > wrote: > > > Matthew, > > You should either use Spring-managed =20 > transactions (via > HibernateTransactionManager or =20 > JtaTransactionManager), which will > automatically flush a Session at transaction =20= > commit, or set > HibernateTemplate's/HibernateInterceptor's =20 > "flushMode" property to > FLUSH_EAGER (respectively "flushModeName" to =20= > "FLUSH_EAGER" in a > textual bean definition). This will guarantee =20= > to flush as early as > possible, not after view rendering: After all, = =20 > a view should not > modify the model, so there should be no need =20= > to flush afterwards. > > Juergen > > > ________________________________ > > Von: =20 > spr...@li... im Auftrag > von Matthew E. Porter > Gesendet: Di 09.12.2003 02:20 > An: =20 > spr...@li... > Betreff: [Springframework-developer] =20 > OpenSessionInViewFilter > > > > I am attempting to use the =20 > OpenSessionInViewFilter. According to the > javadoc, the session is not flush at the end =20= > of the filter. Therefore, > without overriding the closeSession() method =20= > in the filter, how do I > get the session to flush? I am currently =20 > accessing DAOs wrapped as a > ProxyFactoryBean with a HibernateInterceptor. > > Please help! > > > Cheers, > matthew > > > > =20 > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux =20= > Tutorials. > Become an expert in LINUX or just sharpen your = =20 > skills. Sign up for > IBM's > Free Linux Tutorials. Learn everything from =20= > the bash shell to sys > admin. > Click now! =20 > http://ads.osdn.com/?ad_id=3D1278&alloc_id=3D3371&op=3Dclick > = _______________________________________________ > Springframework-developer mailing list > = Spr...@li... > =20 > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > > > =20 > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux =20= > Tutorials. > Become an expert in LINUX or just sharpen your = =20 > skills. Sign up for > IBM's > Free Linux Tutorials. Learn everything from =20= > the bash shell to sys > admin. > Click now! =20 > http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick > = _______________________________________________ > Springframework-developer mailing list > = Spr...@li... > =20 > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > > > = ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux = Tutorials. > Become an expert in LINUX or just sharpen your skills. = =20 > Sign up for IBM's > Free Linux Tutorials. Learn everything from the bash =20= > shell to sys admin. > Click now! =20 > http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > =20 > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux Tutorials. > Become an expert in LINUX or just sharpen your skills. Sign up = =20 > for IBM's > Free Linux Tutorials. Learn everything from the bash shell to =20= > sys admin. > Click now! http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclic= k > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > =20 > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux Tutorials. > Become an expert in LINUX or just sharpen your skills. Sign up for =20= > IBM's > Free Linux Tutorials. Learn everything from the bash shell to sys =20 > admin. > Click now! http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dick > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux Tutorials. > Become an expert in LINUX or just sharpen your skills. Sign up for =20= > IBM's > Free Linux Tutorials. Learn everything from the bash shell to sys =20 > admin. > Click now! http://ads.osdn.com/?ad_id=1278&alloc_id371&op=3Dclick > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
From: Cameron B. <ca...@da...> - 2003-12-10 03:30:02
|
There is a way to access sorceforge and never receive an IOException : use the following pserver details : Server : cvs-pserver.sourceforge.net Port : 443 This was mentioned on the sf site somewhere in regards to getting access to cvs from behind a firewall. Since I have changed over to this server/port, I havn't had any problems with access. Cameron Matthew E. Porter wrote: > You are welcome. FWIW: The bruise from banging my head against this > is healing nicely. Thanks for fixing it. Now, only if cvs at > sourceforge would ever work.... > > > > Cheers, > matthew > > On Dec 9, 2003, at 2:22 PM, jürgen höller [werk3AT] wrote: > >> BTW, that didn't affect normal HibernateTransactionManager >> transactions at all, just ones with pre-bound Session - for which >> OpenSessionInViewFilter is the first practical use case. And thanks >> for early-adopting the filter! :-) >> >> Mike, please update from CVS too if you're trying the >> OpenSessionInViewFilter! >> >> Juergen >> >> >> ________________________________ >> >> Von: spr...@li... im >> Auftrag von jürgen höller [werk3AT] >> Gesendet: Di 09.12.2003 21:14 >> An: Matthew E. Porter >> Cc: spr...@li... >> Betreff: Re: [Springframework-developer] OpenSessionInViewFilter >> >> >> >> Matthew, >> >> 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. >> >> It works nicely for me now, for example with Petclinic. I hope the >> public CVS server shows the changed HibernateTransactionManager >> source file promptly. >> >> Juergen >> >> >> ________________________________ >> >> Von: Matthew E. Porter [mailto:ma...@me...] >> Gesendet: Di 09.12.2003 20:56 >> An: jürgen höller [werk3AT] >> Betreff: Fwd: [Springframework-developer] OpenSessionInViewFilter >> >> >> Do you think this is a bug with Spring? >> >> >> Cheers, >> matthew >> >> Begin forwarded message: >> >> >> From: Matthew E. Porter <ma...@me...> >> Date: December 9, 2003 7:35:04 AM CST >> To: spr...@li... >> Subject: Re: [Springframework-developer] >> OpenSessionInViewFilter >> Reply-To: spr...@li... >> >> Juergen: >> FWIW: I am using the OpenSessionInViewFilter with Webwork2. >> >> 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. >> >> Any guesses? >> >> >> Cheers, >> matthew >> >> On Dec 9, 2003, at 7:03 AM, jürgen höller [werk3AT] wrote: >> >> >> Matthew, >> >> 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. >> >> 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. >> >> 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: >> >> <property name="transactionAttributes"> >> <props> >> <prop key="*">PROPAGATION_REQUIRED</prop> >> </props> >> </property> >> >> 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. >> >> Juergen >> >> >> -----Original Message----- >> From: Matthew E. Porter [mailto:ma...@me...] >> Sent: Tuesday, December 09, 2003 1:51 PM >> To: jürgen höller [werk3AT] >> Subject: Re: [Springframework-developer] >> OpenSessionInViewFilter >> >> >> Juergen: >> Here is what I currently have that is not working. >> >> <bean id="OSUserDaoTarget" >> >> class="com.metissian.security.principal.provider.osuser.configuration.O >> S >> UserManagerDAO"> >> <property name="sessionFactory"> >> <ref local="MetalSessionFactory"/> >> </property> >> </bean> >> >> <bean id="OSUserDao" >> >> class="org.springframework.transaction.interceptor.TransactionProxyFact >> o >> ryBean"> >> <property name="transactionManager"> >> <ref local="MetalTransactionManager"/> >> </property> >> <property name="target"> >> <ref local="OSUserDaoTarget"/> >> </property> >> <property name="transactionAttributes"> >> <props> >> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> >> <prop key="delete*">PROPAGATION_REQUIRED</prop> >> <prop key="update*">PROPAGATION_REQUIRED</prop> >> <prop key="save*">PROPAGATION_REQUIRED</prop> >> </props> >> </property> >> </bean> >> >> >> For some reason, I believed that wrapping an object >> in a >> TransactionProxyFactoryBean provided the >> transactionality you talked >> about. Am I wrong? >> >> >> Cheers, >> matthew >> >> On Dec 9, 2003, at 12:45 AM, jürgen höller [werk3AT] >> wrote: >> >> >> Matthew, >> >> You should either use Spring-managed >> transactions (via >> HibernateTransactionManager or >> JtaTransactionManager), which will >> automatically flush a Session at transaction >> commit, or set >> HibernateTemplate's/HibernateInterceptor's >> "flushMode" property to >> FLUSH_EAGER (respectively "flushModeName" to >> "FLUSH_EAGER" in a >> textual bean definition). This will >> guarantee to flush as early as >> possible, not after view rendering: After >> all, a view should not >> modify the model, so there should be no need >> to flush afterwards. >> >> Juergen >> >> >> ________________________________ >> >> Von: >> spr...@li... im Auftrag >> von Matthew E. Porter >> Gesendet: Di 09.12.2003 02:20 >> An: >> spr...@li... >> Betreff: [Springframework-developer] >> OpenSessionInViewFilter >> >> >> >> I am attempting to use the >> OpenSessionInViewFilter. According to the >> javadoc, the session is not flush at the end >> of the filter. Therefore, >> without overriding the closeSession() method >> in the filter, how do I >> get the session to flush? I am currently >> accessing DAOs wrapped as a >> ProxyFactoryBean with a HibernateInterceptor. >> >> Please help! >> >> >> Cheers, >> matthew >> >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: IBM Linux >> Tutorials. >> Become an expert in LINUX or just sharpen >> your skills. Sign up for >> IBM's >> Free Linux Tutorials. Learn everything from >> the bash shell to sys >> admin. >> Click now! >> http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click >> _______________________________________________ >> Springframework-developer mailing list >> Spr...@li... >> >> https://lists.sourceforge.net/lists/listinfo/springframework-developer >> >> >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: IBM Linux >> Tutorials. >> Become an expert in LINUX or just sharpen >> your skills. Sign up for >> IBM's >> Free Linux Tutorials. Learn everything from >> the bash shell to sys >> admin. >> Click now! >> http://ads.osdn.com/?ad_id78&alloc_id371&op=click >> _______________________________________________ >> Springframework-developer mailing list >> Spr...@li... >> >> https://lists.sourceforge.net/lists/listinfo/springframework-developer >> >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: IBM Linux Tutorials. >> Become an expert in LINUX or just sharpen your >> skills. Sign up for IBM's >> Free Linux Tutorials. Learn everything from the bash >> shell to sys admin. >> Click now! >> http://ads.osdn.com/?ad_id78&alloc_id371&op=click >> _______________________________________________ >> Springframework-developer mailing list >> Spr...@li... >> >> https://lists.sourceforge.net/lists/listinfo/springframework-developer >> >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: IBM Linux Tutorials. >> Become an expert in LINUX or just sharpen your skills. Sign >> up for IBM's >> Free Linux Tutorials. Learn everything from the bash shell >> to sys admin. >> Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click >> _______________________________________________ >> Springframework-developer mailing list >> Spr...@li... >> >> https://lists.sourceforge.net/lists/listinfo/springframework-developer >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: IBM Linux Tutorials. >> Become an expert in LINUX or just sharpen your skills. Sign up for >> IBM's >> Free Linux Tutorials. Learn everything from the bash shell to sys >> admin. >> Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=ick >> _______________________________________________ >> Springframework-developer mailing list >> Spr...@li... >> https://lists.sourceforge.net/lists/listinfo/springframework-developer >> >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: IBM Linux Tutorials. >> Become an expert in LINUX or just sharpen your skills. Sign up for >> IBM's >> Free Linux Tutorials. Learn everything from the bash shell to sys >> admin. >> Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click >> _______________________________________________ >> Springframework-developer mailing list >> Spr...@li... >> https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux Tutorials. > Become an expert in LINUX or just sharpen your skills. Sign up for IBM's > Free Linux Tutorials. Learn everything from the bash shell to sys admin. > Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > -- Any damn fool can write code that a computer can understand... The trick is to write code that humans can understand. [Martin Fowler http://www.martinfowler.com/distributedComputing/refactoring.pdf] |
|
From: Les A. H. <le...@ha...> - 2005-11-21 13:37:25
|
Sorry, I didn't get to finish my previous email (hit shortcut key for
'send' by accident).
It is not recommended to implement this type of behavior in a Hibernate
application. An application-transaction is scoped to a few connected
request/response cycles and shouldn't be used across a user's entire
interaction with the system - doing otherwise creates much greater
conflict for stale data and versioning conflicts.
Also, I'm not sure why you'd want to do this in the first place -
sessions are extremely lightweight objects that are meant to be created
and destroyed at the beginning and end of a single request,
respectively. They are only meant to be disconnected/reconnected across
multiple requests when those requests are related to what Hibernate
calls an "application transaction": when visiting multiple pages in
succession build up data context and that accumulated data should be
commited or rolled back at the same instant of time - think of a
web-based wizard, where at the end of step 4, only then should
everything be committed to the database.
If you're trying to enhance performance of the application (and
Hibernate is the only process accessing the database), it is more
efficient and better form to enable a 2nd-level cache (instead of using
the Session itself for that purpose).
From the Hibernate documentation:
"This pattern [long-lived session] is problematic if the Session is too
big to be stored during user think time, e.g. an HttpSession should be
kept as small as possible. As the Session is also the (mandatory)
first-level cache and contains all loaded objects, we can probably use
this strategy only for a few request/response cycles. This is indeed
recommended, as the Session will soon also have stale data."
Regards,
Les
P.S. I should also note that storing a Hibernate Session in an
HttpSession will cause problems in a clustered environment - its usually
better to maintain a stateless programming paradigm across the entire
application and enable the second cache if you ever envision software
being run in a clustered and/or striped deployment.
On Sun, 20 Nov 2005 20:29:21 -0500, "Artem Ploujnikov"
<bla...@ca...> said:
> Some Web application frameworks like JSF might require you to extend
> the
> lifetime of a persistent entity beyond a single HTTP request. What I am
> proposing is an alternative implementation of OpenSessionInViewFilter
> that
> opens one Hibernate session per HTTP session instead of one session per
> request. JDBC connection management should not be a problem because it is
> possible to disconnect and reconnect Hibernate sessions without closing
> them.
>
> Here is the filter that I'm using in my application... I think it would
> be a
> good idea to include something similar in a future release of Spring.
> Please
> note that it hasn't been well tested, and it requires a session filter
> that
> closes orphaned sessions.
>
> public class HibernateSessionFilter extends OncePerRequestFilter {
> public static final String DEFAULT_SESSION_FACTORY_BEAN_NAME =
> "sessionFactory";
> public static final String SESSION_KEY = "org.foo.web.hibernateSession";
>
> private String sessionFactoryBeanName =
> DEFAULT_SESSION_FACTORY_BEAN_NAME;
>
> /**
> * @return Returns the sessionFactoryBeanName.
> */
> protected String getSessionFactoryBeanName() {
> return sessionFactoryBeanName;
> }
>
>
> /**
> * @param sessionFactoryBeanName The sessionFactoryBeanName to set.
> */
> public void setSessionFactoryBeanName(String sessionFactoryBeanName) {
> this.sessionFactoryBeanName = sessionFactoryBeanName;
> }
>
>
> protected SessionFactory lookupSessionFactory() {
> if (logger.isDebugEnabled()) {
> logger.debug("Using SessionFactory '" + getSessionFactoryBeanName() +
> "'
> for OpenSessionInViewFilter");
> }
> WebApplicationContext wac =
> WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
> return (SessionFactory) wac.getBean(getSessionFactoryBeanName(),
> SessionFactory.class);
> }
>
> protected void doFilterInternal(
> HttpServletRequest request, HttpServletResponse response, FilterChain
> filterChain)
> throws ServletException, IOException {
> SessionFactory sessionFactory = lookupSessionFactory();
> HttpSession httpSession = request.getSession();
> Session session =
> (Session) httpSession.getAttribute(SESSION_KEY);
> if (session == null) {
> session = sessionFactory.openSession();
> httpSession.setAttribute(SESSION_KEY, session);
> }
> if (!session.isConnected()) {
> session.reconnect();
> }
> TransactionSynchronizationManager.bindResource(sessionFactory, new
> SessionHolder(session));
> try {
> filterChain.doFilter(request, response);
> } finally {
> TransactionSynchronizationManager.unbindResource(sessionFactory);
> session.disconnect();
> }
>
> }
>
> }
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
> Register for a JBoss Training Course. Free Certification Exam
> for All Training Attendees Through End of 2005. For more info visit:
> http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|