diff --git a/docs/src/main/asciidoc/datasource.adoc b/docs/src/main/asciidoc/datasource.adoc index f2fd2bbaa1f03..b86be090ced8e 100644 --- a/docs/src/main/asciidoc/datasource.adoc +++ b/docs/src/main/asciidoc/datasource.adoc @@ -301,7 +301,8 @@ Oracle has a very weird behavior of committing the uncommitted transactions on c Which means that when stopping Quarkus for instance, in progress transactions might be committed even if incomplete. -Given that is not the expected behavior and that it could lead to data loss, we added an interceptor that rolls back any unfinished transactions at connection close. +Given that is not the expected behavior and that it could lead to data loss, we added an interceptor that rolls back any unfinished transactions at connection close, +provided you are not using XA (in which case the transaction manager handles things for you). If this behavior introduced in 3.18 causes issues for your specific workload, you can disable it by setting the `-Dquarkus-oracle-no-automatic-rollback-on-connection-close` system property to `true`. Please take the time to report your use case in our https://github.com/quarkusio/quarkus/issues[issue tracker] so that we can adjust this behavior if needed. diff --git a/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/RollbackOnConnectionClosePoolInterceptor.java b/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/RollbackOnConnectionClosePoolInterceptor.java index 26719f1cd5642..8be1aa101feab 100644 --- a/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/RollbackOnConnectionClosePoolInterceptor.java +++ b/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/RollbackOnConnectionClosePoolInterceptor.java @@ -5,6 +5,7 @@ import org.jboss.logging.Logger; import io.agroal.api.AgroalPoolInterceptor; +import io.agroal.pool.wrapper.ConnectionWrapper; import oracle.jdbc.OracleConnection; /** @@ -38,6 +39,13 @@ public void onConnectionDestroy(Connection connection) { return; } + // do not rollback XA connections, they are handled by the transaction manager + if (connection instanceof ConnectionWrapper connectionWrapper) { + if (connectionWrapper.getHandler().getXaResource() != null) { + return; + } + } + try { if (connection.unwrap(Connection.class) instanceof OracleConnection oracleConnection) { if (connection.isClosed() || connection.getAutoCommit()) { @@ -50,4 +58,4 @@ public void onConnectionDestroy(Connection connection) { LOG.trace("Ignoring exception during rollback on connection close", e); } } -} \ No newline at end of file +}