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.com>wrote: > 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 ThreadLocal<Session> requestCycleThread = new > ThreadLocal<Session>(); > > /** Keys for session factories that have been opened for this request */ > //protected static HashSet keys = new HashSet(); > > public static ThreadLocal<Session> 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 > >