jwcarman wrote:
> 
> Are you positive that hibernate will write this data to the session?
> The default flush mode of Spring's OpenSessionInViewFilter is "NEVER":
> 
> ... you retrieve it using a DAO/Repository with a transaction demarcation
> of readOnly/required ...
> 

yeah, that's right. But there are some use cases where Hibernate *will*
flush. For example Hibernate will flush when calling a service method (not
read-only) that for some reason decides not to save the user, e.g.

public void checkAndSaveUser(User u) {
        if (user.getUsername().length() > 3) saveOrUpdate(u);
}

This will flush at the end of the transaction.

Another situation is where you start multiple transaction, e.g. to register
a user to different groups.

public void onSubmit() {
        User user = (User) getModelObject();
        for (Group group : user.getGroups()) {
                service.registerUserForGroup(user, group);
        }
}

I agree, these might be some strange examples. But the point is, if you
don't want changes to be persisted, you have to take care that between the
beginning and the end of the request there are no (non-read-only)
transactional service methods called. [As mentioned, the OSIV-Filter
defaults to FlushMode.NEVER, so it won't flush by itself].

Another possibility is to use Wicket's validation capabilities, as Igor
mentioned. Unlike other frameworks (I think Spring MVC is an example),
Wicket validators get called before anything is written in to the model
objects. So it's okay to call service methods from those validators.



-- 
View this message in context: 
http://www.nabble.com/OpenSessionInView-%28OSIV%29%2C-LoadableDetachableModel-and-Transactions-tp18115802p18140556.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to