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