title: How can I fix JndiException on hibernate?
body: <pre><code>public class HibernateUtil {
  private static SessionFactory sessionFactory = createSessionFactory();
  private static ServiceRegistry serviceRegistry;
  
  public static SessionFactory createSessionFactory() {
      Configuration configuration = new Configuration();
      configuration.configure();
      serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
              configuration.getProperties()).build();
      sessionFactory = configuration.buildSessionFactory(serviceRegistry);
      return sessionFactory;
  }
  
  public static SessionFactory getSessionFactory() {
      return sessionFactory;
  }
  }
  </code></pre>
  
  <p>This is the class I have found on this forum to provide the session factory
  but I keep getting the <code>JndiException: Error parsing JNDI name []</code></p>
  
  <pre><code>16:07:57,659 WARN SessionFactoryObjectFactory:98 - Could not bind factory to JNDI
  </code></pre>
  
  <p>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:640)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
      at javax.naming.InitialContext.getNameParser(InitialContext.java:429)
      at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
      at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
      at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:293)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145)
      at util.HibernateUtil.(HibernateUtil.java:13)</p>