ibatis独立事务处理
String resource="SqlMapConfig.xml";
Reader reader = null;
try {
reader =
Resources.getResourceAsReader(resource);
} catch (IOException e1) {
// TODO Auto-generated
catch block
e1.printStackTrace();
}
SqlMapClient smc =
SqlMapClientBuilder.buildSqlMapClient(reader);
spring编程事务处理
transactionTemplate =
(TransactionTemplate)factory.getBean("transactionTemplate");
List<Testtb> tbs = null;
tbs =
transactionTemplate.execute(new
TransactionCallback(){
public Object doInTransaction(TransactionStatus
ts){
try
{
}
catch (Exception e)
{
ts.setRollbackOnly();
}
finally
{
}
}
});
spring 声明事务
<?xml version="1.0"
encoding="UTF-8"?>
<beans
xmlns="
xmlns:xsi="
xmlns:p="
xmlns:aop="
xmlns:tx="
xsi:schemaLocation="
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean
>
<property>
<value>jdbc.properties</value>
</property>
</bean>
<bean
>
<property>
<value>java:comp/env/jdbc/mysqlDB</value>
</property>
</bean>
<!--
<bean
>
<property>
<value>${jdbc.driver}</value>
</property>
<property>
<value>${jdbc.url}</value>
</property>
<property>
<value>${jdbc.username}</value>
</property>
<property>
<value>${jdbc.password}</value>
</property>
</bean>
-->
<bean >
<property ref="dataSource" />
</bean>
<bean>
<property
ref="transactionManager"/>
</bean>
<aop:config>
<aop:pointcut expression="execution(*
com.ibc.service.*.*(..))"/>
<aop:advisor
advice-ref="txAdvice"
pointcut-ref="pointcut1"/>
</aop:config>
<tx:advice
transaction-manager="transactionManager">
<tx:attributes>
<tx:method isolation="READ_COMMITTED"
propagation="REQUIRED"
rollback-for="java.lang.Exception"/>
</tx:attributes>
</tx:advice>
<tx:annotation-driven transaction-manager="transactionManager"/>