Hi, i have exactly the same problem .. Here's my config file
Code:
<hibernate-configuration>
<session-factory name="">
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver:URL###</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.username">NAME</property>
<property name="connection.password">PASS</property>
<property name="hibernate.default_schema">dbo</property>
<mapping class="za.co.epsilon.domain.OverrideItemDo" />
<mapping class="za.co.epsilon.domain.BatchOverrideDo" />
<mapping class="za.co.epsilon.domain.TaskOverrideDo" />
</session-factory>
</hibernate-configuration>
error
Code:
16:19:01,029 INFO NamingHelper:49 - JNDI InitialContext properties:{}
16:19:01,029 WARN SessionFactoryObjectFactory:121 - Could not bind factory to JNDI
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:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.getNameParser(InitialContext.java:480)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:75)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:113)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:365)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
at za.co.epsilon.factory.dao.HibernateUtil.configure(HibernateUtil.java:153)
at za.co.epsilon.factory.dao.HibernateUtil.rebuildSessionFactory(HibernateUtil.java:135)
at za.co.epsilon.factory.dao.HibernateUtil.getSessionFactory(HibernateUtil.java:105)
at za.co.epsilon.test.BatchOverrideHibernateTest.getSession(BatchOverrideHibernateTest.java:22)
at za.co.epsilon.test.BatchOverrideHibernateTest.init(BatchOverrideHibernateTest.java:47)
at za.co.epsilon.test.BatchOverrideHibernateTest.main(BatchOverrideHibernateTest.java:34)
16:19:01,029 INFO BatchOverrideHibernateTest:58 - ---- Exception occurred : org.hibernate.HibernateException : No CurrentSessionContext configured!
org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:683)
at za.co.epsilon.test.BatchOverrideHibernateTest.getSession(BatchOverrideHibernateTest.java:22)
at za.co.epsilon.test.BatchOverrideHibernateTest.init(BatchOverrideHibernateTest.java:47)
at za.co.epsilon.test.BatchOverrideHibernateTest.main(BatchOverrideHibernateTest.java:34)
hibernateUtil
Code:
public static SessionFactory getSessionFactory() {
String sfName = configuration.getProperty(Environment.SESSION_FACTORY_NAME);
if ( sfName != null && !sfName.equals("")) {
log.debug("Looking up SessionFactory in JNDI");
try {
return (SessionFactory) new InitialContext().lookup(sfName);
} catch (NamingException ex) {
throw new RuntimeException(ex);
}
} else if (sessionFactory == null) {
sessionFactory = new Configuration().configure().buildSessionFactory();
}
return sessionFactory;
}
as you can see, "Environment.SESSION_FACTORY_NAME" does not exist on my hibernate config file...