我想用spring配置hibernate.cfg.xml文件以使用事务管理器。这是我的代码
的hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">
jdbc:sqlserver://localhost\none:1433;databaseName=DATA</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="Model/TaiKhoan.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Account.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 16, 2016 11:24:56 AM by Hibernate Tools 4.3.1 -->
<hibernate-mapping>
<class name="Model.TaiKhoan" table="TAI_KHOAN" schema="dbo" catalog="DATA" optimistic-lock="version">
<id name="username" type="string">
<column name="username" length="50" />
<generator class="assigned" />
</id>
<property name="pass" type="string">
<column name="Pass" length="50" />
</property>
</class>
</hibernate-mapping>
应用context.xml中
<?xml version='1.0' encoding='UTF-8' ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
</beans>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
<property name="mappingResources">
<list>
<value>Model.TaiKhoan</value>
</list>
</property>
</bean>
但是当我运行项目时它无法运行。我该如何配置它们? 谢谢!