I am learning about the OSIV pattern and have so far read the
introduction at hibernate.org [1], the Spring JavaDoc for
OpenSessionInViewFilter [2], the excellent MysticCoders tutorial [3]
that uses Spring's OpenSessionInViewFilter, and some more.
I have basic questions:
1. Is it correct that there are two variants of the pattern?
In one variant there is a single transaction (and a single session)
that gets committed at the end of the request, as described in [1]. If
I am not mistaken, James's wicket-advanced application [5] also uses
this variant.
In the second variant, there is an intermediate commit. We therefore
have two transactions (and one or two Hibernate sessions). Examples
for this are WicketRAD and the London-Wicket PDF [4].
2. The first variant has the disadvantage that the code handling the
request cannot handle errors itself as the commit takes place at the
end of the request, in a filter. Correct?
As a concrete example, this means that if my code inserts an item that
already exists and does not explicitly check for duplicates, the
request will result in a rollback and the default error page. Where I
would have preferred to see a feedback message "This item already
exists". (It seems to me, however, that it is not a good practice to
move error checking concerns to the database integrity layer, so the
code *should* check for duplicates...)
4. Which variant(s) doe Spring's OpenSessionInViewFilter support and
how does it work?
I do not fully understand the documentation of the class but have the
feeling it implements the second, and you can specify whether you want
a single or two Hibernate sessions. I read [3]:
"NOTE: This filter will by default not flush the Hibernate Session,
with the flush mode set to FlushMode.NEVER. It assumes to be used in
combination with service layer transactions that care for the
flushing: The active transaction manager will temporarily change the
flush mode to FlushMode.AUTO during a read-write transaction, with the
flush mode reset toFlushMode.NEVER at the end of each transaction. If
you intend to use this filter without transactions, consider changing
the default flush mode (through the "flushMode" property)."
Here is my understanding of this, assuming I have configured a Spring
transaction manager and use transaction annotations:
When a request starts, a Hibernate session is opened. When the first
method with a @Transactional annotation is encountered, a transaction
is started, and Hibernate's session is associated with this
transaction. When the method exits, the transaction is committed but
the session is left open (the OSIV behaviour). At the end of the
request, the session is closed. Is this correct?
Thanks for a reply and sorry for the lengthy post,
Kaspar
--
[1] http://www.hibernate.org/43.html
[2]
http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html
[3]
http://www.mysticcoders.com/blog/2009/03/13/5-days-of-wicket-putting-it-all-together/
[4]
http://code.google.com/p/londonwicket/downloads/detail?name=LondonWicket-OpenSessionInView.pdf&can=2&q=
[5] http://markmail.org/message/ittmrmwsn5l6usx7
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org