Hibernate: Is it possible to bind a SessionFactory to a JNDI name?

There is a way to set the JNDI name of SessionFactory in the hibernate.cfg.xml file. However, if I do not explicitly use the JNDI search to get my SessionFactory at all in my web application, is it okay to give it a JNDI name?

I ask the question that if I did not configure my JNDI name, my JUnit tests will work fine. But if I installed it, specifying only the "name" in the sessionfactory tag in the hibernate.cfg.xml file, it will say first:

WARN  [WebApp:SessionFactoryObjectFactory.addInstance] Could not bind factory to JNDI

and throw exception:

javax.naming.NoInitialContextException:Need to specify class name in environment or system property, or as an appletparameter, or in an application resource file:

So, I need to remove the JNDI name from my hibernate.cfg.xml, but I don’t know if this will cause other problems or not?

+3
source share
2 answers

, , hibernate.cfg.xm JUnit.

+3

, = "sessionFactory" .

0

Source: https://habr.com/ru/post/1704976/


All Articles