Repository navigation
Conversation
…en a transaction is active In an optimistic transaction there is no datastore transaction until the first flush, so a stored procedure ran on a separate connection. Since 4.2.0 that connection leaves auto-commit mode when the procedure has OUT parameters and is only committed when the result provider is closed, which does not happen before the EntityManager closes the connection, so the changes of the procedure were rolled back. Begin the datastore transaction first, as native queries and bulk updates do, so that commit and rollback of the transaction apply to the procedure.
…ases of the database builds Create the procedure for PostgreSQL, MySQL, MariaDB, SQL Server, Oracle and HSQLDB as well as for Derby, so that the database builds run the test. H2 is skipped, it has no SQL procedures with OUT parameters.
solomax
reviewed
Nov 27, 2026
|
|
||
| @Test | ||
| void changesAreCommittedWithTheTransaction() { | ||
| EntityManager em = emf.createEntityManager(); |
Contributor
There was a problem hiding this comment.
Maybe try-with-resource should be used in this test?
solomax
approved these changes
Nov 27, 2026
…saction test with try-with-resources
rzo1
marked this pull request as ready for review
November 27, 2026 08:57
cristof
approved these changes
Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://issues.apache.org/jira/browse/OPENJPA-3100
Reported on users@: since 4.2.0, the changes of a stored procedure with an OUT parameter are not committed by
EntityTransaction.commit()when the transaction is optimistic (the default), unlessOpenJPAEntityManager.beginStore()is called first.Cause: in an optimistic transaction there is no datastore transaction until the first flush, and
StoredProcedureQuery.executeQuery()did not start one, so the procedure ran on a separate connection. In 4.1.1 that connection was in auto-commit mode, so the changes were committed at once (and could not be rolled back). Since OPENJPA-2940 (88e7709) the connection leaves auto-commit mode when the procedure has OUT parameters and is only committed inXROP.close(), which does not run before the EntityManager closes the connection, so the changes were rolled back.Fix: when a transaction is active, call
beginStore()before taking the connection, as native queries (SQLStoreQuery) and bulk updates (JDBCStoreQuery) already do. The procedure then runs on the connection of the transaction, and commit and rollback apply to it. Outside a transaction nothing changes, including the REF_CURSOR handling.Reproduced on PostgreSQL 18 with a PL/pgSQL procedure that deletes rows and has a BIGINT OUT parameter:
beginStore(), after commitTests: new
TestStoredProcedureTransaction(commit and rollback of a procedure with an OUT parameter in an optimistic transaction) creates the procedure on Derby, PostgreSQL, MySQL, MariaDB, SQL Server, Oracle and HSQLDB, so the database builds run it; H2 is skipped (no SQL procedures with OUT parameters). Run locally on all of them: it passes with the fix and fails without it (on SQL Server the changes even survived the rollback). On Derby, the stored procedure tests inorg.apache.openjpa.jdbc.procedure,TestNativeQueryProcedures,TestEntityManagerTCKComplianceand the openjpa-lib, openjpa-kernel and openjpa-jdbc suites pass.TCK and the database builds pass on this branch: TCK https://github.com/apache/openjpa/actions/runs/45953368744, Databases https://github.com/apache/openjpa/actions/runs/45953372759 (on 42c1601; the later commit only changes how the test closes its entity managers).