一个方法同时实现一个修改和新增数据。某一个失败就事务回滚。一下是方法和事务配置:
public void updateSteelTagCheckingConfirm(String steelTagId,String recReviseTime,String status,String recRevisor) throws Exception
{
List list = steelPipeLabelDao.querySteelTagChecking();
SteelTagCheckingModel steelTagCheckingModel = (SteelTagCheckingModel) list.get(0);
steelTagCheckingModel.setId(null);
steelTagCheckingModel.setRecCreateTime(new Date());
steelTagCheckingModel.setRecReviseTime(new Date());
steelTagCheckingModel.setStatus(status);
steelTagCheckingModel.setRecRevisor(recRevisor);
steelPipeLabelDao.querySteelTagCheckingConfirm(steelTagId);//修改
steelPipeLabelDao.insertSteelTagCheckingConfirm(steelTagCheckingModel);//新增
}
以下是SPring事务配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
default-autowire="no">
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:bsteel.properties</value>
<value>classpath:javaMail.properties</value>
</list>
</property>
</bean>
<!-- Pool DataSource
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="loginTimeout">
<value>1800</value>
</property>
<property name="maxStatements">
<value>50</value>
</property>
<property name="maxStatementsPerConnection">
<value>20</value>
</property>
<property name="minPoolSize">
<value>5</value>
</property>
<property name="maxPoolSize">
<value>30</value>
</property>
<property name="acquireIncrement">
<value>2</value>
</property>
<property name="driverClass">
<value>${jdbc.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${jdbc.url}</value>
</property>
<property name="user">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>
-->
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingDirectoryLocations">
<list>
<value>
hibernate3/com/baosight/baosteel/bsi/cs/qs/model
</value>
<value>
hibernate3/com/baosight/baosteel/bsi/cs/rf/model
</value>
<value>
hibernate3/com/baosight/baosteel/bsi/cs/ct/model
</value>
<value>
hibernate3/com/baosight/baosteel/bsi/cs/sv/model
</value>
<!-- add by TanGuiyuan -->
<value>
hibernate3/com/baosight/baosteel/bsi/cs/sv2/model
</value>
<value>
hibernate3/com/baosight/baosteel/bsi/cs/oq/model
</value>
<value>
hibernate3/com/baosight/baosteel/bsi/common/model
</value>
<value>
hibernate3/com/baosight/baosteel/bsi/helper/model
</value>
<value>
hibernate3/com/baosight/baosteel/bsi/cs/fq/model
</value>
<!-- added by frankie 2008-5-4 -->
<value>
hibernate3/com/baosight/baosteel/bsi/cs/ce/bxgHistory/model
</value>
<value>
hibernate3/com/baosight/baosteel/bsi/cs/ce/baoxin/model
</value>
<value>
hibernate3/com/baosight/baosteel/bsi/cs/ce/luobao/model
</value>
<value>
hibernate3/com/baosight/baosteel/bsi/cs/ce/model
</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.use_minimal_puts">true</prop>
<prop key="hibernate.max_fetch_depth">2</prop>
<prop key="hibernate.show_sql">true</prop>
<prop
key="hibernate.bytecode.use_reflection_optimizer">
true
</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
</props>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="baseTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<!--<prop key="*">PROPAGATION_REQUIRED</prop> -->
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED</prop>
<prop key="query*">PROPAGATION_REQUIRED</prop>
<prop key="list*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>