Jboss xa resource ORA-02089: COMMIT is not allowed in a subordinate session
目前使用的是EJB3+JPA1.0的框架下,但是由于特殊需要,需要在服务端执行arbitrarysql(DDL语句),经过多方查证,发现EntityManager.createNativeQuery无法执行DDL语句,所以只能使用JDBC来实现。
在不使用XADataSource的情况下,sqlServer2005/Oracle都运行正常,但是在使用XADataSource+oracle的时候,出现如下错误:
ava.sql.SQLException:ORA-02089:COMMIT不允许在附属会话中
atoracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
atoracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
atoracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
atoracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
atoracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:207)
atoracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:946)
atoracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1168)
atoracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1687)
atoracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1653)
atorg.jboss.resource.adapter.jdbc.WrappedStatement.execute(WrappedStatement.java:91)
atcom.hanthink.common.db.agent.DBExecute.execute(DBExecute.java:33)
atcom.hanthink.framework.coreserver.datahandlers.ATRowDataHandler.createTable(ATRowDataHandler.java:170)
atcom.hanthink.framework.coreserver.datahandlers.ATDefinitionDataHandler.saveContainedObjects(ATDefinitionDataHandler.java:108)
atcom.hanthink.framework.coreserver.sessionbeans.ATDefinitionBean.saveATDefinition(ATDefinitionBean.java:154)
atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
atjava.lang.reflect.Method.invoke(Method.java:597)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
atorg.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
atorg.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:76)
atorg.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:62)
atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
atjava.lang.reflect.Method.invoke(Method.java:597)
atorg.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
atorg.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_676831891.invoke(InvocationContextInterceptor_z_fillMethod_676831891.java)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
atorg.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_676831891.invoke(InvocationContextInterceptor_z_setup_676831891.java)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
atorg.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.security.RunAsSecurityInterceptorv2.invoke(RunAsSecurityInterceptorv2.java:94)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
atorg.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
atorg.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:421)
atorg.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:53)
atorg.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)
atorg.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
atorg.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:897)
atorg.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:768)
atorg.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:721)
atorg.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:548)
atorg.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:234)
目前解决的思路有两个:
1、不要再SessionBean中使用事务
2、使用两个数据源,一个JTA数据源,主要用于JPA;另外一个Locale数据源,供JDBC使用
目前没有找到好的解决办法,只能先通过方案2来解决