weixin_42220324
2008-08-19 01:12
浏览 154
已采纳

Spring+JDBC事务配置

[code="java"]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

 <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName"  
        value="com.mysql.jdbc.Driver" />
    <property name="url" 
    value="jdbc:mysql://localhost:3306/mucun?useUnicode=true&amp;characterEncoding=utf-8&amp;useOldAliasMetadataBehavior=true"></property>
    <property name="username" value="root"></property>  
    <property name="password" value=""></property>          
    <property name="validationQuery" value="select 1" />                
    <property name="maxIdle" value="5" /> 
    <property name="maxWait" value="100" />  
    <property name="maxActive" value="20" />
</bean>

<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource">
        <ref local="dataSource" />
    </property>
</bean> 

<bean id="abstractTxDefine" lazy-init="true"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
        <ref bean="transactionManager" />
    </property>
    <property name="transactionAttributes">
        <props>
            <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
        </props>
    </property>       
</bean>

<bean id="sqlMapClient"
    class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation">
        <value>WEB-INF/classes/sqlMapConfig.xml</value>
    </property>
    <property name="dataSource">
        <ref bean="dataSource"></ref>
    </property>
</bean>
<bean id="sqlMapDao"
    class="com.charity.common.dao.impl.SqlMapDaoUtilsImp">
    <property name="sqlMapClient" ref="sqlMapClient"/>
</bean> 

<bean id="jdbcDao" class="com.charity.common.dao.impl.JdbcDaoUtilsImp">
    <property name="dataSource">  
        <ref local="dataSource" />
    </property>
</bean>

<bean id="serviceManager" lazy-init="true" 
    class="com.charity.common.service.impl.ServiceManager">
    <property name="sqlMapDao">
        <ref bean="sqlMapDao" />
    </property>
    <property name="jdbcDao">
        <ref bean="jdbcDao" />
    </property>
</bean>

<bean id="multiTableFormdataService" parent="abstractTxDefine">
    <property name="target">
        <bean parent="serviceManager"
            class="com.charity.common.service.impl.MultiTableFormdataService">
        </bean>
    </property>
</bean>


[/code]

class MultiTableFormdataService extends ServiceManager{
实现业务代码
}
class ServiceManager {
jdbcDao;
sqlMapDao;

}
问题:
结果是在MultiTableFormdataService 类中多表保存,并没有因为某条语句错误而产生事务回滚。

不知道问什么,请指教

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • lggegegmail 2008-08-19 09:48
    已采纳

    [code="java"] class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> [/code]

    [code="java"] [/code]

    所以, 已经给multiTableFormdataService加了事务.

    建议LZ查看自己mysql的engine是否不是InnoDB的.

    [code="sql"]show table status from table_name; [/code]

    已采纳该答案
    打赏 评论
  • aidiyuxin 2008-08-19 08:35

    [code="java"]#

    [/code]

    你的dao上没有加事物啊
    不知道你是怎么用的,dao应该也加上事物啊,要不用dao处理东西的时候当然不会回滚啦

    打赏 评论
  • iteye_14762 2008-08-19 10:06

    [code="java"]
    class="com.charity.common.service.impl.MultiTableFormdataService">


    [/code]
    这种写法很新颖, 哈哈, 第一次见到!
    建议将这个bean抽出来按照平常的方式写, 试试看, 只当是一个测试!

    打赏 评论

相关推荐 更多相似问题