Torsten Liermann created JCR-5239:
-------------------------------------

             Summary: ConnectionHelper rejects setAutoCommit/commit/rollback on 
JCA-managed XA connection during active JTA transaction
                 Key: JCR-5239
                 URL: https://issues.apache.org/jira/browse/JCR-5239
             Project: Jackrabbit Content Repository
          Issue Type: Bug
          Components: jackrabbit-data
    Affects Versions: 2.22.2
         Environment:   Reproduced on:
  - Apache Jackrabbit 2.22.2
  - WildFly 35.0.1.Final (IronJacamar)
  - MS SQL Server 2022 via SQLServerXADataSource
  - Java 21
            Reporter: Torsten Liermann


When ConnectionHelper runs against a JCA-managed connection pool
  (IronJacamar / WildFly, JBoss EAP) and the calling thread holds an
  active container-managed JTA transaction, three direct JDBC
  transaction-control calls fail:

  * startBatch()                  -> setAutoCommit(false)
  * endBatch(commit/rollback)     -> connection.commit() / .rollback()
  * getConnection() (JCR-1013)    -> setAutoCommit(true)

  IronJacamar rejects them on a managed XA connection because the
  transaction manager owns the connection's transactional lifecycle:

    IJ031017: You cannot set autocommit during a managed transaction
    IJ031018: You cannot commit during a managed transaction
    IJ031019: You cannot rollback during a managed transaction

  This blocks every Jackrabbit-Classic deployment that wants to share
  its DataSource with a Jakarta-EE JTA boundary, including stacks that
  need 2PC across JPA + JCR on the same backend.

  Proposed fix: resolve a TransactionSynchronizationRegistry once via
  JNDI (java:comp/TransactionSynchronizationRegistry), check
  getTransactionStatus() on each call, and skip the three direct JDBC
  tx-control calls when a managed transaction is in progress. When no
  managed transaction is active the historical behaviour is preserved.

  The TSR is referenced through reflection so the same class compiles
  and runs against javax.transaction (Java EE 8) and jakarta.transaction
  (Jakarta EE 9+).

  Patch and demo of the issue + fix:
  - Branch: github.com/torsten-liermann/jackrabbit 
feature/jta-aware-connection-helper
  - Commit: e126c87
  - The change touches one file (jackrabbit-data ConnectionHelper.java),
    ~111 lines added, 9 lines changed; no behavioural change outside an
    active managed JTA transaction.

  A pull request will follow once this ticket is created.




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to