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的支持引起的,数据库管理员要执行上面的两个步骤,这个错误没什么规律,时而好使。我先遇到了,可能大家以后都不会遇到了
weblogic 分布式事务处理经常遇到的XA异常处理方法
最新推荐文章于 2023-10-07 11:18:51 发布
本文介绍了使用WebLogic XA驱动程序时常见的XA异常及其处理方法。针对“XAER_PROTO”错误,需设置'SupportsLocalTransaction'为true并正确管理本地事务;针对“XAER_RMERR”错误,则需确保数据库已进行适当的XA准备。
摘要由CSDN通过智能技术生成