我有相同的数据要提交到两个不同的MySQL数据库。一旦它在其中一个中更新、插入、删除,它就应该立即在另一个中更新、插入、删除,否则两者都会回滚。

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="t1Datasource"
    <property name="mappingResources">
        <list>
            <value>content/name.hbm.xml</value>
            <value>conten/desg.hbm.xml</value>
        </list>
    </property>
</bean>

我应该为另一个数据库创建一个新会话还是有其他进程?

最佳答案

如果我这样做,我将2 connection managers,一个指向databaseA,另一个指向databaseB,然后在我的数据访问层中,将auto commit设置为false,transact at databaseA,然后如果事务成功,我将transact to数据库b,然后如果成功,commit connection 1 then commit connection 2否则回滚这两个

关于mysql - 具有相同类型实体但数据库不同的多个数据源,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12995947/

10-11 03:21
查看更多