Riyad Kalla wrote:
Thank you for the snippet. Although what you said about misuse made me wonder, am I doing something I shouldn't be doing? Is there an alternative strategy for storing Hibernate sessions in an easy-to-access location that you would employ that is Wicket friendly?

Why are you trying to store hibernate sessions in your Session anyway?
You should be opening a hibernate session for each wicket *request*, not for each wicket user session.

There are various options.

Spring contains an OpenSessionInViewFilter for Hibernate (which is a standard Servlet API ServletFilter). This will open a single session at the beginning of each request and close it when the request ends. You should be hooking all this up to a database connection pool to make it efficient.

If most of your pages do database access, and especially if you need to have JSPs or similar co-exist with Wicket inside your webapp, this is often the best way to go.

If you're concerned that you don't want to always have a session open, write your own ServletFilter with a static method to get a Hibernate Session. This should opens a Hibernate Session if one hasn't already been opened for this request, and store it in a ThreadLocal, so you can retrieve it throughout the request. It should then obviously close the session and flush the ThreadLocal at the end of the request/response cycle. This gives you sort-of lazy-initialisation of your Hibernate session, which is something that IMHO the Spring code should do, but doesn't seem to.

Al


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to