2

我正在使用hibernate在java中尝试一个基本程序......但我得到以下错误描述

WARN: HHH000277: Could not bind factory to JNDI
org.hibernate.service.jndi.JndiException: Error parsing JNDI name [hiber]
    at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92)
    at org.hibernate.service.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:108)
    at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java:89)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:480)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
    at manageEmployee.main(manageEmployee.java:26)
Caused by: 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(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getNameParser(Unknown Source)
    at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86)
    ... 6 more

Exception in thread "main" java.lang.ClassCastException: org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction cannot be cast to javax.transaction.Transaction
    at manageEmployee.addEmployee(manageEmployee.java:44)
    at manageEmployee.main(manageEmployee.java:34)
4

3 回答 3

7

我通过从我的休眠配置文件中的打开会话工厂标签中删除名称属性来解决此问题,使其如下所示:

<session-factory>

代替

<session-factory name="">
于 2013-07-03T12:10:44.723 回答
2

如果发现以下内容,请检查您的导入声明:

import javax.transaction.Transaction;

然后将其替换为:

import org.hibernate.Transaction;

并从所有地方删除投射找到你正在投射的地方,如下所示:

 tx = (Transaction) session.beginTransaction();

消除

(交易)

从所有地方删除铸件。

于 2017-10-17T19:38:38.490 回答
0

这可能是由于缺少一些休眠的依赖库,或者您导入了一些具有相同名称的错误库。

于 2013-07-03T12:12:01.637 回答