测试用例:通过 DruidXADataSource 获取 XA 连接,调用 XA start
@Test public void testXADataSourceNormal() throws Throwable { DruidXADataSource druidDataSource = new DruidXADataSource(); druidDataSource.setUrl(oracle_jdbcUrl); druidDataSource.setUsername(oracle_username); druidDataSource.setPassword(oracle_password); druidDataSource.setDriverClassName(oracle_driverClassName);
XAConnection xaConnection = druidDataSource.getXAConnection();
XAResource xaResource = xaConnection.getXAResource();
Xid xid = XAXidBuilder.build("127.0.0.1:8091:1234", 1235L);
xaResource.start(xid, XAResource.TMNOFLAGS);
}
报错:
oracle.jdbc.xa.OracleXAException: XAErr (-3): A resource manager error has occured in the transaction branch. ORA-6550 SQLErr (0)
at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1112) at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:265) at io.seata.rm.datasource.XAModeTest2.testXADataSourceNormal(XAModeTest2.java:378) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:628) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:117) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:184) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:180) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:127) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at java.util.ArrayList.forEach(ArrayList.java:1257) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at java.util.ArrayList.forEach(ArrayList.java:1257) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229) at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197) at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.sql.SQLException: ORA-06550: 第 1 行, 第 14 列: PLS-00201: 必须声明标识符 'JAVA_XA.XA_START_NEW' ORA-06550: 第 1 行, 第 7 列: PL/SQL: Statement ignored
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:494) at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:446) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1054) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:623) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:252) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:612) at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:223) at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:56) at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:907) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1119) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3780) at oracle.jdbc.driver.T4CCallableStatement.executeInternal(T4CCallableStatement.java:1300) at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3887) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4230) at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1079) at oracle.jdbc.xa.client.OracleXAResource.doStart(OracleXAResource.java:309) at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:260) ... 52 more
Caused by: Error : 6550, Position : 13, Sql = begin :1 := JAVA_XA.xa_start_new(:2 ,:3 ,:4 ,:5 ,:6 ); end;, OriginalSql = begin ? := JAVA_XA.xa_start_new(?,?,?,?,?); end;, Error Msg = ORA-06550: 第 1 行, 第 14 列: PLS-00201: 必须声明标识符 'JAVA_XA.XA_START_NEW' ORA-06550: 第 1 行, 第 7 列: PL/SQL: Statement ignored
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:498) ... 68 more
而相同的逻辑,使用 ORACLE 驱动包中原生的 XA 数据源 OracleXADataSource 就没有问题:
@Test public void testXADataSourceNative() throws Throwable { OracleXADataSource nativeXADataSource = new OracleXADataSource(); nativeXADataSource.setURL(oracle_jdbcUrl); nativeXADataSource.setUser(oracle_username); nativeXADataSource.setPassword(oracle_password); nativeXADataSource.setDriverType(oracle_driverClassName);
XAConnection xaConnection = nativeXADataSource.getXAConnection();
XAResource xaResource = xaConnection.getXAResource();
Xid xid = XAXidBuilder.build("127.0.0.1:8091:1234", 1235L);
xaResource.start(xid, XAResource.TMNOFLAGS);
}
运行正常。
ojdbc 驱动:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.1.0</version>
</dependency>
和
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>
都一样的结果。
ORACLE 数据库:11gR2 Express Edition
原提问者GitHub用户sharajava
主要可能的原因有:
数据源配置错误
检查Druid XA数据源相关配置,常见错误包括:
url、username、password配置不正确
driverClass 配置错误,非oracle.jdbc.OracleDriver
不支持的Oracle驱动版本
其他参数配置值非法
Oracle数据库配置问题
如Oracle方面相关参数设置不当,如:
并发连接数限制太低
数据库用户权限不足
部分Oracle特性未启用
这些都可能影响Druid使用XA特性。
Oracle JDBC驱动不支持XA功能
需要使用支持XA的Oracle JDBC驱动,如:
ojdbc6.jar 11.2.0.2 及以上版本
ojdbc7.jar 12.1.0.1及以上版本
ojdbc8.jar 12.2.0.1 及以上版本
事务管理器配置不正确
主要是使用的事务管理器(如Atomikos)与Oracle JDBC驱动支持不兼容。
需要匹配对应的版本。
Bug
部分Druid和Oracle驱动版本存在Bug,导致XA功能不能正常工作。
可以尝试升级到最新版本。
初步测试,把 com.alibaba.druid.util.OracleUtils#OracleXAConnection 实现改为 T4CXAConnection 就没有问题了。
原回答者GitHub用户sharajava
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。