Can't get Hibernate SessionFactory from JNDI in EAP6.
Issue
We are having issues with JNDI lookups, specifically relating to Hibernate Session Factories. We want to store a session factory in JDNI so that we only initialize it once.
I'm using hibernate session factory name property as described here.
I've attached a zip containing 3 maven projects. One is a util project that contains HibernateUtil which initializes the session factory. It checks to see if the session factory is in JNDI. The other two projects are two simple WARs that each have a servlet that tries to access the session factory. If you deploy them you can get to the servlet by going to web1/MyServlet1 and web2/MyServlet2. It requires you have a mysql database set up called test with a user test using password test.
As you can see from the screenshot I've attached, the hibernate session factory is being put into JDNI at the location I've specified.
But what you can see from the log output is that the first time you access HibernateUtil.getSessionFactory (via MyServlet1), it throws a NameNotFoundException - which you would expect. The second time you access it (via MyServlet2) it does NOT throw an exception, it simply returns null. This tells me that the JNDI lookup understands that there is an object bound to that JNDI name, but for some reason it returns null.
Environment
Red Hat JBoss Enterprise Application Platform (EAP)
-6.x
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.