Spring jdbc事务没有提交

时间:2014-11-04 10:10:52

标签: spring transactions jdbctemplate autocommit

我有以下Spring配置:

   <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:tx="http://www.springframework.org/schema/tx"       
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx       http://www.springframework.org/schema/tx/spring-tx-2.0.xsd        
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" >

具有数据库和事务管理的Bean配置如下:

<bean id="sufe.ncm.docDao" class="DocDaoImpl" scope="singleton">
    <property name="jdbcTemplate" ref="sufe.ncm.jdbcTemplate"/>        
</bean>

<bean id="sufe.ncm.jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="sufe.ncm.filterDB"/>
    <property name="fetchSize" value="5000"/>
</bean>

<bean id="sufe.ncm.filterDB" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="defaultAutoCommit" value="false" />
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="..."/>
    <property name="username" value="..."/>
    <property name="password" value="..."/>
    <property name="initialSize" value="1"/>
    <property name="minIdle" value="1"/>
    <property name="maxIdle" value="5"/>
    <property name="maxOpenPreparedStatements" value="5"/>
</bean>

<context:annotation-config/>
<tx:annotation-driven  transaction-manager="transactionManager"/>
<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="sufe.ncm.filterDB"></property>
</bean>

DocDaoImpl类实现接口updateData中的方法DocDao

    @Transactional(rollbackFor = SQLException.class, propagation = Propagation.REQUIRES_NEW)
    public synchronized void updateData() {
        jdbcTemplate.batchUpdate(UPDATE_QUERY_1);
        jdbcTemplate.batchUpdate(UPDATE_QUERY_1);
    }

因为dataSource已将false设置为autocommit选项,所以我希望只有当两个batchUpdates操作完成无错误时才会提交事务。不幸的是,除非两个更新完成没有错误,否则不执行提交,我没有看到数据库中的任何更改。怎么了 ?为什么@Transactional注释不起作用并且未执行提交?

0 个答案:

没有答案