Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在sharding-jdbc-example-mybatis中,shardingContext.xml配置shardingDataSource,使用bean方式的话,支持事务回滚,但使用rdb:data-source方式的话,事务不会回滚 #74

Closed
Ericj100 opened this issue May 16, 2016 · 1 comment

Comments

@Ericj100
Copy link
Contributor

shardingContext-rdb.xml配置:

 <context:component-scan base-package="com.dangdang.ddframe.rdb.sharding.example.jdbc"/>

    <bean id="ds_0" 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/ds_0"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
    </bean>

    <bean id="ds_1" 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/ds_1"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
    </bean>

    <rdb:strategy id="databaseStrategy" sharding-columns="user_id" algorithm-expression="ds_${user_id.longValue() % 2}"/>

    <rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id.longValue() % 2}"/>

    <rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-class="com.dangdang.ddframe.rdb.sharding.example.jdbc.algorithm.SingleKeyModuloTableShardingAlgorithm"/>

    <rdb:data-source id="shardingDataSource">
        <rdb:sharding-rule data-sources="ds_0,ds_1">
            <rdb:table-rules>
                <rdb:table-rule logic-table="t_order" actual-tables="t_order_${0..1}" database-strategy="databaseStrategy" table-strategy="orderTableStrategy"/>
                <rdb:table-rule logic-table="t_order_item" actual-tables="t_order_item_0,t_order_item_1" database-strategy="databaseStrategy" table-strategy="orderItemTableStrategy"/>
            </rdb:table-rules>
        </rdb:sharding-rule>
        <rdb:props>
            <prop key="metrics.enable">false</prop>
        </rdb:props>
    </rdb:data-source>
@Ericj100
Copy link
Contributor Author

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

    <tx:annotation-driven transaction-manager="transactionManager" />

少配置了事务管理导致的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants