chakravarthyBatna opened a new pull request, #31327:
URL: https://github.com/apache/camel/pull/31327

   # Description
   
   https://issues.apache.org/jira/browse/CAMEL-27886 (points 1 and 2)
   
   Inside a Spring transaction the `spring-jdbc` producer gets the connection 
of the transaction through `DataSourceUtils`, but:
   
   - with the default `resetAutoCommit=true`, 
`processingSqlBySettingAutoCommit` never checks `isConnectionTransactional`: it 
turns off auto-commit, commits after the statement and calls 
`Connection.close()`. The work is committed early, and the transaction manager 
then fails on the closed connection (`TransactionSystemException: JDBC rollback 
failed ... The object is already closed` with H2).
   - with `resetAutoCommit=false`, a transactional connection goes to the 
deferred branch that was added for `outputType=StreamList` (CAMEL-19256), so it 
is closed when the exchange is done, which inside a `TransactionTemplate` / 
`@Transactional` caller is before the commit.
   
   `JdbcProducer.process` now gets the connection first and runs the 
auto-commit handling only when the connection is not transactional. Connections 
are given back through a new default method 
`ConnectionStrategy.releaseConnection(Connection, DataSource)` (closes, so 
plain `camel-jdbc` is unchanged), which `SpringConnectionStrategy` implements 
with `DataSourceUtils.releaseConnection`. The option descriptions of 
`resetAutoCommit` and `connectionStrategy`, the spring-jdbc page and the 4.25 
upgrade guide are updated.
   
   Point 3 of the ticket (the inherited `transacted` text) is already handled 
on `main`: the option is deprecated and its text no longer points to 
spring-jdbc.
   
   Tests: `JdbcSpringTransactionTest` runs an insert through `spring-jdbc` 
inside a `TransactionTemplate` with `DataSourceTransactionManager`, for both 
values of `resetAutoCommit`: a rollback leaves no row, and two inserts in one 
transaction are both committed. All 4 cases fail on `main` with the 
closed-connection error. `camel-jdbc` (72 + 3) and `camel-spring-jdbc` (6) 
tests pass.
   
   # Checklist
   
   - [x] Targets `main`
   - [x] JIRA issue filed
   - [x] Meaningful commit subject and body
   - [ ] Ran `mvn clean install -DskipTests` from root (built the affected 
modules; the catalog copies and the endpoint/component DSL javadoc were updated 
to match the regenerated component JSON)
   - [x] AI-assisted: commit has a `Co-authored-by` trailer
   
   _Prepared with Claude Code on behalf of chakravarthyBatna._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to