hibernate

Hibernate – WARN: HHH000374: Could not unbind factory from JNDI

Symptom

When run application with hibernate outside JEE environment we get follow warning

WARN: HHH000277: Could not bind factory to JNDI
org.hibernate.engine.jndi.JndiException: Error parsing JNDI name []
	at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:141)
	at org.hibernate.engine.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:157)
	at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java:103)
	at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:497)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
....
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
	at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
	at javax.naming.InitialContext.getNameParser(InitialContext.java:499)
	at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:135)
	... 7 more

Cause

The above issue occur cause you specific name on your hibernate configuration file

<hibernate-configuration>
<session-factory name="">
 ....

Solution

When run hibernate application outside JEE environment, you should remove name property from hibernate configuration file as below

<hibernate-configuration>
<session-factory >
  ...

Leave a Reply