In WildFly 14
, I have a @Stateless
bean that runs two selects with different connections/databases:
InitialContext context = new InitialContext();
DataSource ds = (DataSource)context.lookup("jndi/to/db/1");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from table1"); // table1 in db 1
.........
.........
InitialContext context2 = new InitialContext();
DataSource ds2 = (DataSource)context.lookup("jndi/to/db/2");
Connection conn2 = ds2.getConnection(); // <-- here it fails
Statement stmt2 = conn2.createStatement();
ResultSet rs2 = stmt2.executeQuery("select * from table2"); // table2 in db 2
I'm getting a warning in the second select (that also fails):
ARJUNA012140: Adding multiple last resources is disallowed
According to this link, the problem is that I'm running a single transaction with two different databases. Note that the datasources are NOT configured with the XA option, as there are no use cases in my application that update both databases in a single transaction.
The bean where I have the problem is read-only, it only executes two SQL selects.
I tried to annotate the bean method with:
@TransactionAttribute(javax.ejb.TransactionAttributeType.NEVER)
But I get the runtime error:
WFLYEJB0063: Transaction present on server in Never call (EJB3 13.6.2.6)
Why is the transaction present? How to disable it?