If you intend to retry transactions where Hibernate operations have failed,
it's recommended to either not use OpenSessionInViewFilter in the first
place, or to use it in "deferred close mode" (singleSession=false). The
latter is particularly viable with Hibernate 3, in particular with the
"merge" operation used instead of the classic "saveOrUpdate" (avoiding
conflicts between multiple open Sessions for the same thread).
That said, to the best of my knowledge, Session.clear() is a pretty
aggressive reset of the Session's internal state. Effectively, it's
analogous to opening a new Session in many respects. So even if the
Hibernate team dogmatically says "you need to close the Session on any
HibernateException", that's doesn't seem to be quite true when looking at
the semantics of the "clear" operation. And of course, "clear" perfectly
works for any other exception.
Anyway, I recommend to use OpenSessionInViewFilter's "deferred close mode"
when trying to recover transactions while still relying on lazy loading in
views. Just watch out regarding reassociation of existing persistent objects
with new transactions (i.e. "update"/"saveOrUpdate"), which might cause
"already associated with Session" failures here. Preferably use Hibernate3's
"merge" instead, which I would generally recommend.
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf
Of Chris Richardson
Sent: Friday, June 17, 2005 1:16 AM
To: spr...@li...
Subject: [Springframework-developer] Retrying transactions with
OpenSessionInViewFilter
Did anyone have any comments the issue I raised in this post:
http://forum.springframework.org/viewtopic.php?t=6311&highlight=
The Hibernate documentation recommends closing the Session after a
HibernateException is thrown. That was also the recommendation of
someone on the Hibernate team:
http://forum.hibernate.org/viewtopic.php?p=2246627#2246627
However, I noticed that HibernateTransactionManager calls
Session.clear() with the intent to reset the Session to a known state
so that it can be reused by another transaction. This seems to be at
odds with the Hibernate documentation unless the goal was to only
reuse a Session when a non-HibernateException was thrown.
Does anyone have any comments on how to retry transactions when using
OpenSessionInViewFilter?
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=ick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|