java Hibernate 事务管理器问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/268835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate Transaction Manager Issue
提问by toolkit
I am new to Hibernate and attempting to run a java/spring example that retrieves data from a table in MS SqlServer. Everytime I try to run the program, the data source loads ok. But when spring tries to load the session facotry it gets the following error:
我是 Hibernate 的新手,并试图运行一个 java/spring 示例,该示例从 MS SqlServer 中的表中检索数据。每次我尝试运行程序时,数据源都加载正常。但是当 spring 尝试加载会话工厂时,它会收到以下错误:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory'
defined in class path resource [ml/spring/src/applicationContext.xml]:
Instantiation of bean failed; nested exception is
java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
Caused by: java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
Below is the application Context file I am using:
下面是我正在使用的应用程序上下文文件:
<!-- Data source bean -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName">
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value></property>
<property name="url">
<value>jdbc:microsoft:sqlserver://machine:port</value></property>
<property name="username"><value>user</value></property>
<property name="password"><value>password</value></property>
</bean>
<!-- Session Factory Bean -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<list>
<value>authors.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect
</value>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
回答by toolkit
You are missing a JAR file containing the JTA API classes. You probably have one already when you downloaded Hibernate. It should be called something like:
您缺少包含 JTA API 类的 JAR 文件。当您下载 Hibernate 时,您可能已经有了一个。它应该被称为:
jta-1.1.jar
Hope this helps.
希望这可以帮助。

