Instead of doing this:

Onbeginrequest() { mysession=factory.opensession();
mysession.begintransaction(); }

Session getSession() { return mysession; }

Do this:

Onbeginrequest() { mysession=null; }

Session getSession() { if (mysession==null) {
mysession=factory.opensession(); mysession.begintransaction(); } return
mysession; }

Then when an error occurs just reset mysession back to null and next time
you need one you will get a fresh one


-Igor


> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Gili
> Sent: Wednesday, October 19, 2005 11:44 PM
> To: [EMAIL PROTECTED]
> Subject: [Wicket-user] Wicket, Hibernate and StaleObjectStateException
> 
> Hi,
> 
>       I'm trying to figure out how to handle 
> StaleObjectStateException in the context of Wicket. Using the 
> current-state pattern as reference
> (http://www.hibernate.org/42.html) if a 
> StaleObjectStateException is thrown, I'd like to rollback the 
> transaction, close the session, open a new session and 
> transaction and retry the operation. Ideally I want to keep 
> this logic completely out of the Wicket code. I simply don't 
> see how this can be done.
> 
>       For example, say I have a page containing a Form and 
> Form.onSubmit() is invoked and in its body 
> StaleObjectStateException is thrown. Following the "Session 
> per HTTP request" pattern, we're in a new HTTP request (I
> think) but I don't think Wicket will invoke beginRequest() and
> endRequest() before and after Form.onSubmit(). Even if it 
> did, I'd have no way to signal to Wicket to retry the 
> onSubmit() operation by catching the exception outside it.
> 
>       So on the one hand, I don't want to catch the 
> exceptions inside the Wicket code. On the other hand, I can't 
> retry the operation if I catch the exception outside the Wicket code.
> 
>       Your advice would be appreciated.
> 
> Thank you,
> Gili
> --
> http://www.desktopbeautifier.com/
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads, 
> discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
> 
> 
> 




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to