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;
}
}
這是我在這個論壇上發現,提供這個會話工廠 的類,但我不斷收到JndiException: Error parsing JNDI name []
我該如何修復Hibernate上的JndiException?
16:07:57,659 WARN SessionFactoryObjectFactory:98 - Could not bind factory to JNDI
javax.naming.NoInitialContextException:需要環境或系統屬性指定的類名,或者作爲小程序參數或應用程序資源文件中: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.getURLOrDe faultInitCtx(InitialContext.java:280) 在javax.naming.InitialContext.getNameParser(InitialContext.java:429) 在org.hibernate.util.NamingHelper.bind(NamingHelper.java:52) 在org.hibernate.impl。 SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90) 在org.hibernate.impl.SessionFactoryImpl。(SessionFactoryImpl.java:293) 在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145) 在util.HibernateUtil 。(HibernateUtil.java:13)