Spring JTA 事務小記

          實驗一:MySQL 5.0
          采用atomikos的jta事務(要感謝 http://andyao.javaeye.com/)
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
          xmlns:tx="http://www.springframework.org/schema/tx"
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
          ?????????? http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
          ?????????? http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

          <bean id="dataSource" class="com.atomikos.jdbc.SimpleDataSourceBean"
          init-method="init" destroy-method="close">
          <property name="uniqueResourceName">
          <value>mysql/main</value>
          </property>
          <property name="xaDataSourceClassName">
          <!--使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource)-->
          <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
          </property>
          <property name="xaDataSourceProperties">
          <value>URL=jdbc:mysql://localhost:3306/crm?useUnicode=true&amp;characterEncoding=UTF-8;user=root;password=root</value>
          </property>
          <property name="exclusiveConnectionMode">
          <value>true</value>
          </property>
          <property name="connectionPoolSize">
          <value>3</value>
          </property>
          <property name="validatingQuery">
          <value>SELECT 1</value>
          </property>
          </bean>
          <!-- 第二個數據庫 -->
          <bean id="dataSourceB" class="com.atomikos.jdbc.SimpleDataSourceBean"
          init-method="init" destroy-method="close">
          <property name="uniqueResourceName">
          <value>mysql/news</value>
          </property>
          <property name="xaDataSourceClassName">
          <!--
          使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource)
          -->
          <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
          </property>
          <property name="xaDataSourceProperties">
          <value>URL=jdbc:mysql://localhost:3306/crm2?useUnicode=true&amp;characterEncoding=UTF-8;user=root;password=root</value>
          </property>
          <property name="exclusiveConnectionMode">
          <value>true</value>
          </property>
          <property name="connectionPoolSize">
          <value>3</value>
          </property>
          <property name="validatingQuery">
          <value>SELECT 1</value>
          </property>
          </bean>

          <bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" />

          <!-- 第一個數據庫的sqlMapClient -->
          <bean id="sqlMapClient1" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
          <property name="configLocation">
          <!-- 包含第一個數據庫表的map -->
          <value>classpath:SqlMapConfig.xml</value>
          </property>
          <property name="dataSource" ref="dataSource" />
          <property name="lobHandler" ref="lobHandler" />
          </bean>
          <!-- 第二個數據庫的sqlMapClient -->
          <bean id="sqlMapClient2" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
          <property name="configLocation">
          <!-- 包含第一個數據庫表的map -->
          <value>classpath:SqlMapConfig2.xml</value>
          </property>
          <property name="dataSource" ref="dataSourceB" />
          <property name="lobHandler" ref="lobHandler" />
          </bean>

          <!-- Optional: add a log administrator -->
          <bean id="localLogAdministrator"
          class="com.atomikos.icatch.admin.imp.LocalLogAdministrator"/>

          <bean id="userTransactionService"
          ? class="com.atomikos.icatch.config.UserTransactionServiceImp"
          ? init-method="init" destroy-method="shutdownForce">
          ??? <constructor-arg>
          ??????? <!-- IMPORTANT: specify all Atomikos properties here -->
          ??????? <props>
          ??????????? <prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>
          ??????? </props>
          ??? </constructor-arg>
          ??? <property name="initialLogAdministrators">
          ??????? <list>
          ??????????? <ref bean="localLogAdministrator"/>
          ??????? </list>
          ??? </property>
          </bean>
          <!--Construct Atomikos UserTransactionManager,needed to configure Spring -->
          <bean id="AtomikosTransactionManager"
          ????? class="com.atomikos.icatch.jta.UserTransactionManager"
          ????? init-method="init" destroy-method="close"
          ????? depends-on="userTransactionService">
          ?? <!--when close is called,should we force transactions to terminate or not?-->
          ?? <property name="forceShutdown" value="false" />
          </bean>
          ?? <!--Also use Atomikos UserTransactionImp, needed to configure Spring-->
          <bean id="AtomikosUserTransaction"
          ????? class="com.atomikos.icatch.jta.UserTransactionImp"?
          ????? depends-on="userTransactionService">
          ?? <property name="transactionTimeout" value="300" />
          </bean>
          ?? <!-- Configure the Spring framework to use JTA transactions from Atomikos -->
          <bean id="JtaTransactionManager"
          ????? class="org.springframework.transaction.jta.JtaTransactionManager"
          ????? depends-on="userTransactionService">
          ?? <property name="transactionManager" ref="AtomikosTransactionManager" />
          ?? <property name="userTransaction" ref="AtomikosUserTransaction" />
          </bean>

          <bean id="user1Dao" class="com.crm.code.dao.impl.User1DaoImpl">
          <property name="sqlMapClient">
          <ref bean="sqlMapClient1"/>
          </property>
          </bean>
          <bean id="user2Dao" class="com.crm.code.dao.impl.User2DaoImpl">
          <property name="sqlMapClient">
          <ref bean="sqlMapClient2"/>
          </property>
          </bean>
          <bean id="user12Service" class="com.crm.code.service.impl.User12ServiceImpl">
          <property name="user1Dao">
          <ref bean="user1Dao" />
          </property>
          <property name="user2Dao">
          <ref bean="user2Dao" />
          </property>
          </bean>

          </beans>
          這樣是成功的 可是切換oracle9i時悲劇發生了
          --- Cause: com.atomikos.datasource.ResourceException: resume for XID oracle.jdbc.xa.OracleXid@145f939 raised -3: the XA resource detected an internal error
          Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:??
          --- The error occurred in ibatis/Product1.xml.?
          --- The error occurred while executing update.?
          --- Check the????????? insert into boss_product???? (PROD_ID,? PARENT_ID,? APP_ID,? PROD_NAME,? PROD_CODE,? DEFAULT_VER_PROD_ID,? DATA_PATH,? GMT_CREATED,? GMT_MODIFIED,? CREATOR,? MODIFIER,? IS_DELETED)????? values???? (seq_boss_product.nextval,????? 1,????? 88,????? ?,????? ?,????? 10,????? 'aaa',????? sysdate,????? sysdate,????? 'aavv',????? 'aacb',????? 'n')??????? .?

          官方說oracle連接問題 哎。。。無語了
          換了一種JTA事務機制 通過JOTM
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
          xmlns:tx="http://www.springframework.org/schema/tx"
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
          ?????????? http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
          ?????????? http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
          ??????????
          ?? <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>???
          ?? <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">?
          ???????? <property name="userTransaction" ref="jotm"/>
          ?? </bean>??????????
          ???
          ??? <bean id="dataSourceA" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource"?
          ??? destroy-method="shutdown">?
          ??????? <property name="dataSource">
          ???????????? <bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">?
          ???????????????? <property name="transactionManager" ref="jotm"/>?
          ???????????????? <property name="driverName" value="oracle.jdbc.driver.OracleDriver"/>?
          ???????????????? <property name="url" value="jdbc:oracle:thin:@10.2.224.44:1521:trade"/>?
          ???????????? </bean>?
          ???????? </property>?
          ???????? <property name="user" value="crm_aep"/>?
          ???????? <property name="password" value="crm_aep"/>?
          ???? </bean>?

          ??? <bean id="dataSourceB" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource"?
          ??? destroy-method="shutdown">?
          ??????? <property name="dataSource">
          ???????????? <bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">?
          ???????????????? <property name="transactionManager" ref="jotm"/>?
          ???????????????? <property name="driverName" value="oracle.jdbc.driver.OracleDriver"/>?
          ???????????????? <property name="url" value="jdbc:oracle:thin:@10.2.226.24:1521:voucher"/>?
          ???????????? </bean>?
          ???????? </property>?
          ???????? <property name="user" value="boss"/>?
          ???????? <property name="password" value="boss"/>?
          ???? </bean>?

          ??? <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true" />
          ??????????
          <!-- 第一個數據庫的sqlMapClient -->
          <bean id="sqlMapClient1" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
          <property name="configLocation">
          <!-- 包含第一個數據庫表的map -->
          <value>classpath:SqlMapConfig_ora1.xml</value>
          </property>
          <property name="dataSource" ref="dataSourceA" />
          </bean>
          <!-- 第二個數據庫的sqlMapClient -->
          <bean id="sqlMapClient2" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
          <property name="configLocation">
          <!-- 包含第一個數據庫表的map -->
          <value>classpath:SqlMapConfig_ora2.xml</value>
          </property>
          <property name="dataSource" ref="dataSourceB" />
          </bean>


          <bean id="product1Dao" class="com.crm.code.dao.impl.Product1DaoImpl">
          <property name="sqlMapClient">
          <ref bean="sqlMapClient1"/>
          </property>
          </bean>
          <bean id="product2Dao" class="com.crm.code.dao.impl.Product2DaoImpl">
          <property name="sqlMapClient">
          <ref bean="sqlMapClient2"/>
          </property>
          </bean>
          <bean id="product12Service" class="com.crm.code.service.impl.Product12ServiceImpl">
          <property name="product1Dao">
          <ref bean="product1Dao" />
          </property>
          <property name="product2Dao">
          <ref bean="product2Dao" />
          </property>
          </bean>
          </beans>

          posted on 2009-12-09 17:29 飛熊 閱讀(2204) 評論(0)  編輯  收藏 所屬分類: JTA


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 钟山县| 兴义市| 富宁县| 武乡县| 鞍山市| 普宁市| 迁安市| 嫩江县| 中江县| 金秀| 芦溪县| 仙桃市| 托克托县| 岱山县| 江都市| 依安县| 辽源市| 曲周县| 乌恰县| 阜康市| 安康市| 乡城县| 义马市| 卓资县| 肃宁县| 独山县| 雷波县| 阳泉市| 大竹县| 绥中县| 兴安县| 寿阳县| 竹溪县| 鲁甸县| 化隆| 图们市| 获嘉县| 宝兴县| 武功县| 山东| 多伦县|