快乐着飞舞着

---Nothing to do is doing nothing
随笔 - 93, 文章 - 5, 评论 - 56, 引用 - 0
数据加载中……

Hibernate 的错误

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();



posted on 2006-07-23 23:21 快乐着飞舞着 阅读(2472) 评论(1)  编辑 收藏 引用 所属分类: Java

评论

# re: Hibernate 的错误 [未登录]  回复  更多评论   

Make sure that you use exact name hibernate.cfg.xml. The db instance name and schema account name should be upper case in the file. Make sure the password is correct
2007-03-08 23:42 | James
只有注册用户登录后才能发表评论。

Clicky