weblogic 分布式事务处理经常遇到的XA异常处理方法

weblogic 分布式事务处理经常遇到的XA异常处理方法前提:用Weblogic XA类型的驱动程序,选中'SupportLocalTransaction'.
这些错误都默名奇妙,费了好大尽才找到答案.

错误1:
java.sql.SQLException: XA error: XAER_PROTO : Routine was invoked in an inproper context start() failed on resource 'InitialPool': XAER_PROTO : Routine was invoked in an inproper context
javax.transaction.xa.XAException
at oracle.jdbc.xa.OracleXAResource.disallowLocalTxnMode(OracleXAResource.java:1047)
at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:153)
at weblogic.jdbc.wrapper.VendorXAResource.start(VendorXAResource.java:50)
at weblogic.jdbc.jta.DataSource.start(DataSource.java:604)
at weblogic.transaction.internal.XAServerResourceInfo.sta

解决:
If the XA driver supports performing SQL operations with no global transaction, explicitly allow it by setting "SupportsLocalTransaction" JDBC connection pool property to true. In this case, also remember to complete the local transaction before using the connection again for global transaction, else a XAER_OUTSIDE XAException may result. To complete a local transaction, you can either set auto commit to true or call Connection.commit() or Connection.rollback().
也就是说,如果在同一个线程中,对于同一个连接池,先执行本地事务,接着取连接执行分布式事务要么明确用con.setAutoCommit(true),要么用con.setAutoCommit(false)/con.begin/con.rollback来完成本地事务。一般在前台页面开发时会遇到这样的问题:比如先通过InitialWebPublicPara来初始化页面,接着调用别人的EJB方法

最明显的是用下面的例子会出错:
java.sql.Connection con1 =
ConnectionManager.getConnection("BossInitDS");
//con1.setAutoCommit(true);
java.sql.Statement stmt = con1.createStatement();
stmt.executeQuery("select 1 from dual");
stmt.close();
con1.close();

//直接这样,或调用一个EJB方法(EJB方法中取连接)
javax.transaction.UserTransaction ut = weblogic.transaction.TxHelper.getUserTransaction();
ut.begin();
java.sql.Connection con =
ConnectionManager.getConnection("BossInitDS");
ut.commit();
con.close();

错误2:
错误a.ORA-01000: maximum open cursors exceeded
错误b.[java.sql.SQLException: XA error: XAER_RMERR : A resource manager error has occured in the transaction branch start() failed on resource 'weblogic.jdbc.jta.DataSource': XAER_RMERR : A resource manager error has occured in the transaction branch
oracle.jdbc.xa.OracleXAException

at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1159)

at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:311)

at weblogic.jdbc.wrapper.VendorXAResource.start(VendorXAResource.java:50)

at weblogic.jdbc.jta.DataSource.start(DataSource.java:604)

at weblogic.transaction.internal.XAServerResourceInfo.start(XAServerResourceInfo.java:1069)

at weblogic.transaction.internal.XAServerResourceInfo.xaStart(XAServerResourceInfo.java:1001)

at weblogic.transaction.internal.XAServerResourceInfo.enlist(XAServerResourceInfo.java:203)

at weblogic.transaction.internal.ServerTransactionImpl.enlistResource(ServerTransactionImpl.java:419)


解决:
To prepare the database for XA, perform these steps:
1. Log on to sqlplus as system user, e.g.
sqlplus sys/CHANGE_ON_INSTALL@<DATABASE ALIAS NAME>
2. Execute the sql: grant select on DBA_PENDING_TRANSACTIONS to user where user is the user account used to create database connections in a connection pool. Execute this command for each user account used in XA connection pools in your WebLogic Server domain.
If the above steps are not performed on the database server, normal XA database queries and updates may work fine. However, when the Weblogic Server Transaction Manager performs recovery on a re-boot after a crash, recover for the Oracle resource will fail with XAER_RMERR. Crash recovery is a standard operation for an XA resource.
这完全是数据库对XA的支持引起的,数据库管理员要执行上面的两个步骤,这个错误没什么规律,时而好使。我先遇到了,可能大家以后都不会遇到了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值