<?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: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-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="xufeng"></property>
<property name="password" value="123456"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop> </props>
</property>
<property name="mappingResources">
<list>
<value>com/dao/TestTable.hbm.xml</value>
<value>com/dao/Admin.hbm.xml</value>
<value>com/dao/Sales.hbm.xml</value>
<value>com/dao/Books.hbm.xml</value>
</list>
</property>
</bean> <bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<aop:config>
<aop:pointcut id="interceptorPointCuts"
expression="execution(* com.dao.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" />
</aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="load*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="get" read-only="true" />
<tx:method name="bulk*" />
<tx:method name="delete*"   />
<tx:method name="execute*" />
<tx:method name="lock" />
<tx:method name="save*" propagation="REQUIRED"  />
<tx:method name="persist*" />
<tx:method name="update*" propagation="REQUIRED"  />
</tx:attributes>
</tx:advice>
<bean id="TestTableDAO" class="com.dao.TestTableDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="AdminDAO" class="com.dao.AdminDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="SalesDAO" class="com.dao.SalesDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="BooksDAO" class="com.dao.BooksDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</beans>
测试中对多表操作只能对单表回滚。另一张表成功插入。