OSIV with requestCycleListener
Would you recommend using a requestCycleListener to implement the OSIV pattern and storing the hibernate session in a threadlocal ? Any comments ? tips ? public class MyRequestCycleListener extends AbstractRequestCycleListener { private static final ThreadLocalSession requestCycleThread = new ThreadLocalSession(); /** Keys for session factories that have been opened for this request */ //protected static HashSet keys = new HashSet(); public static ThreadLocalSession getRequestCycleThread() { return requestCycleThread; } @Override public void onBeginRequest(RequestCycle cycle) { if (requestCycleThread.get() == null) { Session session = MyRequestCycle.getHibernateSession(null); requestCycleThread.set(session); } } @Override public void onEndRequest(RequestCycle cycle) { if (requestCycleThread.get()!= null){ MyRequestCycle.closeHibernateSessions(); requestCycleThread.set(null); } } -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/OSIV-with-requestCycleListener-tp4493806p4493806.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: OSIV with requestCycleListener
Grazia, Those are good lifecycle events, but consider configuring org.hibernate.context.ManagedSessionContext and using its ThreadLocal. Then client code can use the more conventional SessionFactory#getCurrentSession(). Dan On Wed, Mar 21, 2012 at 2:28 PM, grazia grazia.russolass...@gmail.comwrote: Would you recommend using a requestCycleListener to implement the OSIV pattern and storing the hibernate session in a threadlocal ? Any comments ? tips ? public class MyRequestCycleListener extends AbstractRequestCycleListener { private static final ThreadLocalSession requestCycleThread = new ThreadLocalSession(); /** Keys for session factories that have been opened for this request */ //protected static HashSet keys = new HashSet(); public static ThreadLocalSession getRequestCycleThread() { return requestCycleThread; } @Override public void onBeginRequest(RequestCycle cycle) { if (requestCycleThread.get() == null) { Session session = MyRequestCycle.getHibernateSession(null); requestCycleThread.set(session); } } @Override public void onEndRequest(RequestCycle cycle) { if (requestCycleThread.get()!= null){ MyRequestCycle.closeHibernateSessions(); requestCycleThread.set(null); } } -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/OSIV-with-requestCycleListener-tp4493806p4493806.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: OSIV with requestCycleListener
Thank you for the suggestion, I will try it. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/OSIV-with-requestCycleListener-tp4493806p4493927.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org