[ 
https://issues.apache.org/jira/browse/OPENJPA-2940?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18075784#comment-18075784
 ] 

ASF subversion and git services commented on OPENJPA-2940:
----------------------------------------------------------

Commit ae5072b1e741f354d5f4ee5fd5294a361c3f2c9a in openjpa's branch 
refs/heads/OPENJPA-2940-rzo1 from Richard Zowalla
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=ae5072b1e ]

[OPENJPA-2940] Keep connection open during runWithConnection/callWithConnection 
when tx is active

Per JPA 3.2, the Connection handed to ConnectionConsumer/ConnectionFunction is
on loan to the user code; its lifecycle belongs to the EntityManager/Broker
when a transaction is active. Previously, the finally blocks in both
EntityManagerImpl.runWithConnection and callWithConnection unconditionally
closed the returned wrapper (a ClientConnection around the broker's
RefCountConnection).

On most drivers (Derby, H2, PostgreSQL) the close path is benign because
RefCountConnection._retain is true during an active tx so free() is not
invoked. MariaDB Connector/J 3.5.4, however, reacts more aggressively when
its connection wrapper is closed inside an active transaction and discards
pending work on the underlying connection, causing manual INSERTs issued
from within runWithConnection to be lost. This manifests as
TestCascadeManyToOneAndEM2.testRunWithConnection / testCallWithConnection
failing on MariaDB with "Order should be found ...".

Fix: only close the user-facing connection when no transaction is active,
i.e. when the user borrowed a free-standing connection. During an active
transaction the EM/broker retains ownership of the connection.


> Implement Jakarta Persistence 3.2
> ---------------------------------
>
>                 Key: OPENJPA-2940
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2940
>             Project: OpenJPA
>          Issue Type: Improvement
>            Reporter: Paulo Cristovão de Araújo Silva Filho
>            Priority: Major
>         Attachments: image-2026-03-28-14-55-26-463.png
>
>
> Implement Jakarta Persistence API 3.2 as prescribed by 
> [specification|https://jakarta.ee/specifications/persistence/3.2/] and 
> required by Jakarta EE 11.
> This change requires JDK17 or higher compatibility and needs considerable 
> checks.
> I've already pushed a branch (WIP) without the proper API bump, focusing on 
> updating dependencies while keeping the project passing its current tests at 
> least in default profile.



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

Reply via email to