Steve,
UNC binding as it in jboss-head doesn't work properly.
For example, servlet being called twice simulaneosly (so executed in 2 threads) always accessed last session being bound to jndi.
Just to note: I implemented this a little differently so did't encounter this issue. Will publish my version a little later (I need to prepare it) - now just how to reproduce this bug.
Create servlet like this (with hibernate session filter, of course)
Code:
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Session session1 = HibernateContext.getSession("java:/hibernate/SessionFactory");
System.out.println("POINT1 thread: "+Thread.currentThread()+" session: "+session1);
Thread.sleep(60000);
Session session2 = HibernateContext.getSession("java:/hibernate/SessionFactory");
System.out.println("POINT2 thread: "+Thread.currentThread()+" session: "+session2);
}
Call it from different browser windows near simultaneosly (so the second thread started before Thread.sleep(60000) ended.)
You'll get:
Code:
19:38:12,996 INFO [STDOUT] POINT1 thread: Thread[http-0.0.0.0-8080-Processor22,5,jboss] session: net.sf.hibernate.impl.S
essionImpl@156f1b0
19:38:15,340 INFO [STDOUT] POINT1 thread: Thread[http-0.0.0.0-8080-Processor25,5,jboss] session: net.sf.hibernate.impl.S
essionImpl@52ce2a
19:38:22,996 INFO [STDOUT] POINT2 thread: Thread[http-0.0.0.0-8080-Processor22,5,jboss] session: net.sf.hibernate.impl.S
essionImpl@52ce2a
As you see servlet executed in first thread at POINT2 got session not the same like at POINT1 but the same like thead2 at POINT1.
It just overrides the same ENC.
after that, you'll see exception during second thread's lookup at POINT2: (because first thread just called unbind against it).
Code:
19:38:22,996 DEBUG [FilterInterceptor] Cleaning up after filter execution
19:38:23,011 INFO [HibernateContextHelper] Unbinding Hibernate session from scoped bind [java:/hibernate/SessionFactory]
19:38:23,011 DEBUG [HibernateContextHelper] Completed unbinding
19:38:25,340 ERROR [HibernateContext] Unable to locate current session
javax.naming.NameNotFoundException: SessionFactory not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:530)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:644)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at org.jboss.hibernate.session.HibernateContext.lookupSessionWrapper(HibernateContext.java:71)
at org.jboss.hibernate.session.HibernateContext.lookupSessionWrapper(HibernateContext.java:53)
at org.jboss.hibernate.session.HibernateContext.lookupSession(HibernateContext.java:44)
at org.jboss.hibernate.session.HibernateContext.getSession(HibernateContext.java:39)
....