[ 
https://issues.apache.org/jira/browse/CAMEL-27886?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen updated CAMEL-27886:
--------------------------------
    Description: 
Found while improving the option descriptions of camel-spring-jdbc for 
CAMEL-23832 (commit 
https://github.com/apache/camel/commit/85ea55b80e9f710e1c415febdbba3bc65915daea,
 pull request https://github.com/apache/camel/pull/31155).
These are separate problems of the component; the descriptions change only 
documents the current behavior.

h4. 1. resetAutoCommit=true commits and closes the transaction connection
With the default resetAutoCommit=true, 
{{JdbcProducer.processingSqlBySettingAutoCommit}} (camel-jdbc, which 
camel-spring-jdbc runs) never calls isConnectionTransactional: inside a Spring 
transaction it calls conn.commit() on the connection of the transaction, which 
commits all work so far, and then conn.close() while the transaction is still 
running (with HikariCP the next DataSourceUtils.getConnection in the 
transaction returns the closed proxy, and the commit fails). The doc page says 
to set resetAutoCommit=false, but the default breaks what the component is for.
Proposed change: when connectionStrategy.isConnectionTransactional(conn, ds) is 
true, skip setAutoCommit, commit and rollback and only release the connection; 
or default resetAutoCommit to false for spring-jdbc, with an upgrade guide 
entry.

h4. 2. The connection is closed, not released
With resetAutoCommit=false, a transactional connection is closed with 
Connection.close() when the exchange is done (onDone, closeQuietly), not with 
DataSourceUtils.releaseConnection, and the ConnectionHolder reference count is 
never decremented. When the exchange ends inside an outer Spring transaction (a 
@Transactional bean calling a ProducerTemplate, or a listener container with a 
DataSourceTransactionManager), the connection of the transaction is closed 
before the commit.
Proposed change: add ConnectionStrategy.releaseConnection(Connection, 
DataSource), override it in SpringConnectionStrategy with 
DataSourceUtils.releaseConnection, and use it for all closes in JdbcProducer.

h4. 3. The inherited transacted text points to itself
The camel-jdbc text of transacted says to use the spring-jdbc component, which 
is confusing on the spring-jdbc page.
Proposed change: say to set resetAutoCommit=false.


_Claude Code on behalf of davsclaus_

  was:
Found while improving the option descriptions of camel-spring-jdbc for 
CAMEL-23832 (pull request https://github.com/apache/camel/pull/31155).
These are separate problems of the component; the descriptions change only 
documents the current behavior.

h4. 1. resetAutoCommit=true commits and closes the transaction connection
With the default resetAutoCommit=true, 
{{JdbcProducer.processingSqlBySettingAutoCommit}} (camel-jdbc, which 
camel-spring-jdbc runs) never calls isConnectionTransactional: inside a Spring 
transaction it calls conn.commit() on the connection of the transaction, which 
commits all work so far, and then conn.close() while the transaction is still 
running (with HikariCP the next DataSourceUtils.getConnection in the 
transaction returns the closed proxy, and the commit fails). The doc page says 
to set resetAutoCommit=false, but the default breaks what the component is for.
Proposed change: when connectionStrategy.isConnectionTransactional(conn, ds) is 
true, skip setAutoCommit, commit and rollback and only release the connection; 
or default resetAutoCommit to false for spring-jdbc, with an upgrade guide 
entry.

h4. 2. The connection is closed, not released
With resetAutoCommit=false, a transactional connection is closed with 
Connection.close() when the exchange is done (onDone, closeQuietly), not with 
DataSourceUtils.releaseConnection, and the ConnectionHolder reference count is 
never decremented. When the exchange ends inside an outer Spring transaction (a 
@Transactional bean calling a ProducerTemplate, or a listener container with a 
DataSourceTransactionManager), the connection of the transaction is closed 
before the commit.
Proposed change: add ConnectionStrategy.releaseConnection(Connection, 
DataSource), override it in SpringConnectionStrategy with 
DataSourceUtils.releaseConnection, and use it for all closes in JdbcProducer.

h4. 3. The inherited transacted text points to itself
The camel-jdbc text of transacted says to use the spring-jdbc component, which 
is confusing on the spring-jdbc page.
Proposed change: say to set resetAutoCommit=false.


_Claude Code on behalf of davsclaus_


> camel-spring-jdbc: the jdbc producer commits and closes the connection of a 
> running Spring transaction
> ------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27886
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27886
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-jdbc
>            Reporter: Claus Ibsen
>            Priority: Minor
>             Fix For: 4.25.0
>
>
> Found while improving the option descriptions of camel-spring-jdbc for 
> CAMEL-23832 (commit 
> https://github.com/apache/camel/commit/85ea55b80e9f710e1c415febdbba3bc65915daea,
>  pull request https://github.com/apache/camel/pull/31155).
> These are separate problems of the component; the descriptions change only 
> documents the current behavior.
> h4. 1. resetAutoCommit=true commits and closes the transaction connection
> With the default resetAutoCommit=true, 
> {{JdbcProducer.processingSqlBySettingAutoCommit}} (camel-jdbc, which 
> camel-spring-jdbc runs) never calls isConnectionTransactional: inside a 
> Spring transaction it calls conn.commit() on the connection of the 
> transaction, which commits all work so far, and then conn.close() while the 
> transaction is still running (with HikariCP the next 
> DataSourceUtils.getConnection in the transaction returns the closed proxy, 
> and the commit fails). The doc page says to set resetAutoCommit=false, but 
> the default breaks what the component is for.
> Proposed change: when connectionStrategy.isConnectionTransactional(conn, ds) 
> is true, skip setAutoCommit, commit and rollback and only release the 
> connection; or default resetAutoCommit to false for spring-jdbc, with an 
> upgrade guide entry.
> h4. 2. The connection is closed, not released
> With resetAutoCommit=false, a transactional connection is closed with 
> Connection.close() when the exchange is done (onDone, closeQuietly), not with 
> DataSourceUtils.releaseConnection, and the ConnectionHolder reference count 
> is never decremented. When the exchange ends inside an outer Spring 
> transaction (a @Transactional bean calling a ProducerTemplate, or a listener 
> container with a DataSourceTransactionManager), the connection of the 
> transaction is closed before the commit.
> Proposed change: add ConnectionStrategy.releaseConnection(Connection, 
> DataSource), override it in SpringConnectionStrategy with 
> DataSourceUtils.releaseConnection, and use it for all closes in JdbcProducer.
> h4. 3. The inherited transacted text points to itself
> The camel-jdbc text of transacted says to use the spring-jdbc component, 
> which is confusing on the spring-jdbc page.
> Proposed change: say to set resetAutoCommit=false.
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to