rzo1 opened a new pull request, #326: URL: https://github.com/apache/openjpa/pull/326
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), unless `OpenJPAEntityManager.beginStore()` is called first. ```java tx.begin(); StoredProcedureQuery proc = em.createStoredProcedureQuery("delete_marked_files"); proc.registerStoredProcedureParameter(1, Long.class, ParameterMode.OUT); proc.execute(); proc.getOutputParameterValue(1); tx.commit(); // the deleted rows are still there ``` 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 (88e770947) the connection leaves auto-commit mode when the procedure has OUT parameters and is only committed in `XROP.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: | | without `beginStore()`, after commit | after rollback | |---|---|---| | 4.1.1 | deleted | deleted | | 4.2.0 / master | not deleted | not deleted | | this PR | deleted | not deleted | Tests (Derby): new `TestStoredProcedureTransaction` (commit and rollback of a procedure with an OUT parameter in an optimistic transaction); the commit test fails without the fix. The stored procedure tests in `org.apache.openjpa.jdbc.procedure`, `TestNativeQueryProcedures`, `TestEntityManagerTCKCompliance` and the openjpa-lib, openjpa-kernel and openjpa-jdbc suites pass. Draft: the TCK and the database builds run on this branch first. -- 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]
