我正在嘗試設置事務,但沒有成功。 這裏是我的代碼:如何使用myBatis和Spring設置事務
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="dataSource" class="org.apache.ibatis.datasource.pooled.PooledDataSource">
.......
<property name="defaultAutoCommit" value="false" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis-configuration.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
@Transactional
private void prcessTransaction(...) {
delete(...);
//insert:
for(Item item: itemList){
insert(item)
}
}
<delete id="delete" parameterType="map">
delete from .....
</delete>
<insert id="insert" parameterType="Item">
insert into ....
</insert>
它看起來像prcessTransaction方法不僅是交易,但多套成交。
我使用Spring 3.0.5,3.0.4的MyBatis,MyBatis的彈簧-1.0.1,Tomcat的7.0.19,甲骨文11.1.0.6.0
感謝您的幫助。
你在調用'getSqlMapClientTemplate'(Spring API)還是使用iBATIS API發出iBATIS調用? – atrain
我正在使用iBatis調用。 – user802293
您的數據庫是否支持交易? – kurochenko