ARJUNA012140: Adding multiple last resources is disallowed

非 Y 不嫁゛ 提交于 2021-02-10 14:35:14

问题


I have 2 data source and in a method, I need to write and read from the 2 databases. The database is PostgreSQL and my EAR app runs on wildfly-16.

I can't use 2 database connection in the same method

Ok, I know that because the system can't manage a transaction across the different database.

So I splitted the methods in my ejb :

@TransactionAttribute(TransactionAttributeType.NEVER)
public Response mainMethod(String parameter) {
   method1();
   method2()
}

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void method1(){
    ...write on database 1...
}

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void method2(){
    ...write on database 2...
}

Why am I still getting the same error? Aren't the calls managed by two different transactions?

ARJUNA012140: Adding multiple last resources is disallowed. 
Trying to add LastResourceRecord(XAOnePhaseResource(LocalXAResourceImpl@594d9ba8[connectionListener=677e78 connectionManager=2a095926 warned=false currentXid=< formatId=131077, gtrid_length=29, bqual_length=36, tx_uid=0:ffffc0a86e69:-9dc6f57:5d08b51e:f58, node_name=1, branch_uid=0:ffffc0a86e69:-9dc6f57:5d08b51e:f8a, subordinatenodename=null, eis_name=java:/jboss/datasource/db1 > productName=PostgreSQL productVersion=10.8 (Ubuntu 10.8-0ubuntu0.18.04.1) jndiName=java:/jboss/datasource/db1])), 
but already have LastResourceRecord(XAOnePhaseResource(LocalXAResourceImpl@39fc2dc2[connectionListener=3724f31c connectionManager=39a995fb warned=false currentXid=< formatId=131077, gtrid_length=29, bqual_length=36, tx_uid=0:ffffc0a86e69:-9dc6f57:5d08b51e:f58, node_name=1, branch_uid=0:ffffc0a86e69:-9dc6f57:5d08b51e:f64, subordinatenodename=null, eis_name=java:/jboss/datasource/db2 > productName=PostgreSQL productVersion=10.8 (Ubuntu 10.8-0ubuntu0.18.04.1) jndiName=java:/jboss/datasource/db2]))

回答1:


Annotations use dynamic proxies under the cover and so don't work on private methods nor on public ones called internally (on this). You have to declare your two methods in different EJBs.

Otherwise regarding your error, The system can manage transaction across different resources using XA.

Just switch one of your datasources to xa-datasource and you'll get rid off the problem. Note that you can have one non-xa datasource in an XA transaction thanks to LLRTO but not two (that's the meaning of the arjuna error).



来源:https://stackoverflow.com/questions/56650966/arjuna012140-adding-multiple-last-resources-is-disallowed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!