views:

1330

answers:

1

There is a way to set the JNDI name of a SessionFactory in the hibernate.cfg.xml file. However, if I'm not explicitly using JNDI lookup to get my SessionFactory at all in my web app, is it okay to NOT give it a JNDI name?

The reason I ask is that if I didn't set up my JNDI name, my JUnit tests will run fine. But if I do set it up by only specifying 'name' in the sessionfactory tag in hibernate.cfg.xml, it will first say:

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

and the throw an 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 my get around is to remove the JNDI name from my hibernate.cfg.xml, but don't know if that will cause other problems or not?

+1  A: 

I would say it would be ok most of the times, but you could also consider using a different hibernate.cfg.xm for your JUnit tests.

Maurice Perry