ARJUNA012140: Adding multiple last resources is disallowed

Viewed 4541

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]))
2 Answers

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).

Hey just in case someone comes across this error on my end I forgot to close the connection

finally {
    call.closeAll();
}

this resulted to error:

Could not get a connection from the data source , Adding multiple last resources is disallowed.Current resource is org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@17d3bab6
Related