首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

使用JTA的事务处理(pro spring ch12范例)有关问题

2012-10-26 
使用JTA的事务处理(pro spring ch12范例)问题在实施spring专业开发指南中12章多事务处理范例遇到问题,当

使用JTA的事务处理(pro spring ch12范例)问题
在实施<spring专业开发指南>中12章多事务处理范例遇到问题,当指定由JTA管理的事务执行时,相关代码进入异常抛出部分:
TestControl.java
...
try {
accountManager.insert(account);
} catch (Exception ex) {
failures++;
}
...
每次insert都失败,failures值增加.原代码insert部分如下
public void insert(Account account) {
System.out.println("come on,folks");
doInsert(account);

jmsTemplate.send(queue, new MessageCreator() {

public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("foobar");
}

});

if (random.nextInt(10) > 5) {
System.out.println("Fail now");
throw new IllegalArgumentException("fff");
}
}
将随机函数部分关闭后,所有提交仍无法成功.

配置文件如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="urlMapping" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="accountDao" encoding="UTF-8"?>

<datasources>
<xa-datasource>
<jndi-name>XASpringDS</jndi-name>
<track-connection-by-tx/>
<isSameRM-override-value>false</isSameRM-override-value>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
<xa-datasource-property name="URL">jdbc:oracle:oci8:@orcl</xa-datasource-property>
<xa-datasource-property name="User">jboss</xa-datasource-property>
<xa-datasource-property name="Password">password</xa-datasource-property>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<no-tx-separate-pools/>
</xa-datasource>
<mbean
code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter"
name="jboss.jca:service=OracleXAExceptionFormatter">
<depends optional-attribute-name="TransactionManagerService">
jboss:service=TransactionManager</depends>
</mbean>
</datasources>
(原文中mbean为
<mbean
code="org.jboss.resource.adapter.jdbc.xa.oracle.OracleXAExceptionFormatter"
name="jboss.jca:service=OracleXAExceptionFormatter">
<depends optional-attribute-name="TransactionManagerService">
jboss:service=TransactionManager</depends>
</mbean>
注意code部分类名区别,这是使用手册的bug)

applicationContext-as.xml有人说要将
<bean id="transactionManager" for Resin 2.x, Oracle OC4J (Orion), JOnAS (JOTM), BEA WebLogic
"java:comp/TransactionManager" for Resin 3.x
"java:pm/TransactionManager" for Borland Enterprise Server and Sun Application Server (Sun ONE 7 and later)
"java:/TransactionManager" for JBoss Application Server

当使用2.0版的的spring.jar代替在二楼贴中的1.2.8版spring.jar和aopalliance.jar后(请注意二楼贴中所列文件的大小和时间),部署spring-ch12.ear时,JBOSS的log:
...
2007-01-12 18:45:07,765 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Retrieving JTA UserTransaction from JNDI location [java:comp/UserTransaction]
2007-01-12 18:45:07,765 DEBUG [org.springframework.jndi.JndiTemplate] Looking up JNDI object with name [java:comp/UserTransaction]
2007-01-12 18:45:07,765 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Retrieving JTA TransactionManager from JNDI location [java:comp/TransactionManager]
2007-01-12 18:45:07,765 DEBUG [org.springframework.jndi.JndiTemplate] Looking up JNDI object with name [java:comp/TransactionManager]
2007-01-12 18:45:07,765 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] No JTA TransactionManager found at fallback JNDI location [java:comp/TransactionManager]
org.springframework.transaction.TransactionSystemException: JTA TransactionManager is not available at JNDI location [java:comp/TransactionManager]; nested exception is javax.naming.NameNotFoundException: TransactionManager not bound
Caused by:
javax.naming.NameNotFoundException: TransactionManager not bound
...

至于为何2.0的spring.jar会出现这个问题,"Spring2.0及以后的版本中声明式事务的配置与之前的版本有相当大的不同。主要差异在于不再需要配置TransactionProxyFactoryBean了。" 7 楼 wolf_jack 2007-01-13   楼贴问题基本查出,JTA不能支持代码中的ISOLATION_READ_COMMITTED隔离级别.使用默认级别前述问题消除.

新问题:
1.jms消息发出后,日志:
....
2007-01-13 21:48:49,171 DEBUG [org.jboss.mq.il.uil2.SocketManager] Failed to handle: org.jboss.mq.il.uil2.msgs.CloseMsg22893735[msgType: m_connectionClosing, msgID: -2147483641, error: null]
java.io.IOException: Client is not connected
at org.jboss.mq.il.uil2.SocketManager.internalSendMessage(SocketManager.java:264)
....
很奇怪,因为后面的log显示消息已正确收到并处理.

2.JTA提交报告失败,但在sqlplus中检查,数据已提交
...
2007-01-13 21:48:49,187 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Committing JTA transaction
2007-01-13 21:48:49,250 ERROR [org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory] End transaction failed for XAResource
oracle.jdbc.xa.OracleXAException
at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:962)
at oracle.jdbc.xa.client.OracleXAResource.end(OracleXAResource.java:355)
...

继续等待达人路过.-_-# 8 楼 haihai 2007-03-08   看看我的那个用Weblogic做的spring的jta事务的测试,是声明式的事务 9 楼 zzxanadu 2007-08-31   这几天我也把这个例子实现了一下,JMS和JDBC全局事务都回滚成功,没遇到什么问题啊,你有什么问题??

热点排行