2006-07-23 23:14:53,796 [main] WARN org.hibernate.impl.SessionFactoryObjectFactory - 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:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.getNameParser(InitialContext.java:439)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:291)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at reene.study.hibernate.test.TestMain.main(TestMain.java:19)
疑惑中
待解决....
在网上找到如下内容:
(3)报错:Could not bind factory to JNDI
此错误是配置文件的问题,如果hibernate配置文件有session_factory_name这个变量,<session-factory name="foo"> 会试图将一个SessionFactory实例以foo为名bind到jndi上,而有的application container不支持jndi绑定。把这个变量去掉即可。
解决问题
把引用代码也要修改:
大致改成这样:
1 SessionFactory sf = new Configuration().configure()
2 .buildSessionFactory();
3 Session session = sf.openSession();
4 Transaction tx = session.beginTransaction();