Hi , Thanks for your prompt reply. But the below suggestion "Set the thread context class loader to the web application class loader." will not work in our case as we have our own custom class loader to load the hibernate resources like e.g. hbm files , Entity classes and all. Below is the code snippet : Configuration cfg = new Configuration(); cfg.addInputStream(inputStrm); // This is the input stream of the .hbm file which is in our database and Entity class in this xml to be loaded by our custom class loader only as our Entity classes in the database. cfg.buildMappings();
cfg.buildSessionFactory(); // It fails in JNDI look up if I dont set the web application class loader as context class loader. so ideally if I set my custom class loader as context class loader I am able to load my .hbm files and corresponding Entity classes. If I set the context class loader to wep application class loader my JNDI look-up works but I get class not found exception for my Entity classes referred in the .hbm files. Any idea to solve this? RegardsDinesh From: Mark Thomas Sent: 29-07-2016 16:19 To: Tomcat Users List Subject: Re: How to do a JNDI look up in a different thread On 29/07/2016 11:41, Khandelwal, Dinesh wrote: > > Hi, > > As part of my project , we maintain multiple Hibernate session factoriesand > as building these session factories take lot of time which causes server > totake more time in start-up , we are creating these session factories > indifferent threads.... Each thread creating one factory but when > theconfiguration.buildsessionFactory() [Hibernate internally does JNDI look > upwhich fails]API is called it throws Unable to lookup JNDI > name[java:/comp/env/BFDS]. > > Please note that I am using Tomcat 7 and I have tried multiple JNDI > namecombinations e.g. java: /BFDS , java:global/BFDS , BFDS etc. but nothing > works.Same code works in JBOSS 7 and Websphere. > > Please suggest something. Set the thread context class loader to the web application class loader. Mark