OPENJPA-2940 - Jakarta Persistence 3.2 #142
Conversation
* Updated tentative version to 4.2.0-SNAPSHOT * Updated java version to 17
* Updating project to exclude almost all java.security deprecated calls * Passes default profile tests, but fails with postgres * Fixed some non-deterministic tests that fail with postgresql
* Tested and passed XML support using postgresql-17 as target db
* Replacing string number constructors * Removing dangling SecurityContext references
* removed TestSecurityContext because it is terminally deprecated since 17 and already removed in current JDK versions * updated h2-2 test profile jdbc url to remove strict definition * updated openjpa-slice and openjpa-xmlstore pom system variables definitions * updated GH actions workflows to use test-h2-2 profiles
* Project passes tests on derby, h2-2, postgres:latest, mysql:lts, mariadb:lts
* Updated dependency version * Added API new methods to API implementation classes with methods that throw UnsupportedOperationException, except for four methods in EntityManagerImpl that required proper implementations to pass tests * Project is still passing tests on derby and postgresql, at least
* Added XML JPA 3.2 schema and definitions * Added configuration support by 3.2 version * Added SchemaManager impl and corresponding methods in BrokerFactory interface * Added concrete working (not for h2-2) implementation of SchemaManager methods for JDBCBrokerFactory * Added concrete working impl for EMF#getName()
* Reverting unnecessary changes * Fixing broken map synchronization
* Changing signature of BrokerFactory API on schema dealing validate method * Adding test to check if validate operation throws exception when it fails * Changing GH CI workflow to allow usage of both self-hosted and GH hosted runners * Tested on derby, h2-2, postgresql:latest, mysql:lts, mariadb:lts
* Implementing emf creation passing PersistenceConfiguration
* Removing unused import in BrokerImpl * Implemented new PersistenceUnitUtil load methods
* Moved PUU loading tests to test unit already present * Updated test unit to junit 4.x format
The jpql.treatjoinon.TCustomer entity used @table(name="TCUSTOMER") which collides with xmlmapping.entities.Customer (composite EmbeddedId with NOT NULL countryCode). On shared-DB test infrastructures (MariaDB, PostgreSQL), this caused schema drop/recreate cycles to fail with 'ALTER TABLE TCUSTOMER DROP COLUMN id' since id is a PK in the xmlmapping schema. Rename to TTREAT_CUSTOMER to isolate the tables.
MariaDB Connector/J 3.5.4 reports per-row failure indexes correctly (unlike older Oracle/older drivers that flag the first row of the batch). A prior commit mistakenly grouped MariaDB with Oracle/Postgres in the 'first-row reported' assertion branch. Use the generic per-row assertion for MariaDB.
Instant, LocalDateTime, Date, and Calendar version columns left column precision unset, producing DATETIME(0) on MariaDB/MySQL by default. Two updates within the same whole second stored identical versions, defeating optimistic locking. Request 6 fractional digits (microseconds) in ColumnVersionStrategy.map() for temporal javaTypes when the user has not already specified precision. DATETIME(6) / TIMESTAMP(6) matches what Derby/PostgreSQL already use.
columns" This reverts commit 76e8293.
…B/MySQL MariaDB >= 10.2 and MySQL >= 5.7 support fractional-second precision on DATETIME/TIME columns. Bump dateFractionDigits to 6 inside the existing version-gated block so temporal columns use DATETIME(6)/TIME(6) by default. This fixes optimistic-locking on @Version Instant/LocalDateTime columns where two updates within the same whole second otherwise stored identical versions. Matches PostgreSQL and Derby defaults.
…r.proxy SingleFieldManager.proxy assumed the datastore value for a @TeMPOraL field always matches the field's declared type. Handler strategies (and some JDBC driver paths) can return a Calendar for a java.util.Date field or a Date for a Calendar field, which caused a ClassCastException at runtime (e.g. TCK StoredProcedureQuery Client1 where a GregorianCalendar proxy was assigned to an Employee.hireDate Date field). Coerce between Calendar and Date on store so the proxy receives a value of the correct type regardless of which the handler produced. Also fix a copy/paste bug in ProxyManagerImpl.generateAndLoadProxyCalendar which passed ProxyDate.class as the ancestor class used to resolve the proxy class loader's package/protection domain.
…Connection 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.
MySQL and MariaDB don't support ANSI 'NULLS FIRST' / 'NULLS LAST' on ORDER BY. Route the ordering-suffix emission through DBDictionary.appendNullsPrecedence so dialects can customize. Default implementation emits 'NULLS FIRST' / 'NULLS LAST' unchanged. MySQLDictionary and MariaDBDictionary override to emulate via the '<expr> IS NULL <sort>' auxiliary sort key. The emulation is skipped when MySQL's default NULL ordering (NULLs first for ASC, NULLs last for DESC) already matches the requested precedence.
…DK 24+ Ant's non-forked <java> task installs a SecurityManager to catch System.exit(), but System.setSecurityManager() throws UnsupportedOperationException on JDK 24+. The generator would fail silently (no failonerror), producing no build-time proxy classes and causing TestDetachNoProxy legacy-compat assertions to fail because runtime proxies are never tagged detachable=true. Add fork=true and failonerror=true so the generator runs in a separate JVM and surfaces any errors.
…r config - docker-compose-test-pg17.yml (PostgreSQL 17) - docker-compose-test-mariadb.yml (MariaDB 11.4) - docker-compose-test-mysql.yml (MySQL 8.4) The test-mysql-docker profile still used the obsolete mysql:mysql-connector-java GAV and com.mysql.jdbc.Driver class name. Update to com.mysql:mysql-connector-j and com.mysql.cj.jdbc.Driver so modern MySQL Connector/J (9.x) resolves and connects.
MySQL stores BOOLEAN columns as TINYINT(1). By default, MySQL Connector/J reports them as Types.BIT, which OpenJPA's MappingInfo.mergeColumn coerces as "numeric" and silently upgrades to VARCHAR — defeating SchemaManager.validate() detection of a genuine VARCHAR->BOOLEAN schema drift (TestJDBCSchemaManager.testValidate). Setting transformedBitIsBoolean=true makes Connector/J report TINYINT(1) as Types.BOOLEAN, which isNumericType() excludes. This matches MariaDB Connector/J's default behavior where the same test already passes.
Two PostgreSQL-specific fixes needed to make TestJDBCSchemaManager pass: 1. PostgreSQL's JDBC driver reports native boolean columns as Types.BIT. OpenJPA's generic column-type comparison treats BIT as numeric and silently coerces any VARCHAR mapping to 'upgrade' such columns to VARCHAR, which defeats SchemaManager.validate() detection of a genuine VARCHAR -> BOOLEAN schema drift. Override newColumn() to translate reflected columns whose native type name is 'bool' or 'boolean' back to Types.BOOLEAN so the type comparison treats them as their true logical type. 2. IDENTITY-column sequences are dropped implicitly with their owning table, but OpenJPA's schema reflection may still list the sequence as extant. Override getDropSequenceSQL to emit 'DROP SEQUENCE IF EXISTS' so refresh / truncate actions are idempotent and don't fail with 'sequence "..." does not exist' on PostgreSQL 17.
Truncate is a best-effort operation - the repo SchemaGroup may declare tables the dialect never physically created (e.g. OPENJPA_SEQUENCE_TABLE on dialects that prefer native sequences, or tables owned by generators that were never exercised, or tables qualified by a schema that's not on the connection's current search_path). Set _ignoreErrs around the DELETE FROM statements so individual missing tables are logged as warnings instead of aborting the whole truncate. Fixes TestJDBCSchemaManager.testTruncate on PostgreSQL 17.
…testing MariaDB uses 3306. Putting MySQL on 3307 externally (still 3306 inside the container) lets both run simultaneously on the same host, enabling parallel cross-DB test runs.
|
Did look into MariaDB / MySQL and the local build on my OSX looks good. Maybe some one can some additional runs for the tests? 61e93dd might be worth a direct port to |
|
@rzo1, thanks for the effort. I'll run on mariadb, mysql and pg-18 tomorrow. As soon I have some results, I'll post here. |
|
@rzo1, in a clean build, using jdk17 (minimum java version per spec), pointed to PG-17 and MariaDB. PG tests passed persistence jdbc, but failed at locking tests (TestPessimisticLocks::testQueryAfterFindWithPessimisticLocks). I startup the pg docker using And create the test database afterwards (docker exec -it openjpa-pg createdb openjpa). The tests are run using, from the directory where I've pulled the branch and provided a uid/gid equals to 1000:1000: |
|
I am on OSX and using the committed docker-compose.yaml files to run the databases from my dev setup (so I actually have an IDE to debug :D ) - can also run in docker, but will take a few days until I can come back to it :) Although it shouldn't matter if the docker containers are managed via docker-compose or native. Most likely it is related to the Java version, so I will go down to testing with Java 17. |
…orts on MariaDB MariaDB changed batch-failure reporting semantics between server 11.4 and 11.8 (with Connector/J 3.5.4 unchanged): 11.4 reports the actual duplicate row, 11.8 reports the first row of the failing batch, same as Oracle/Postgres. Commit 83e933a assumed per-row was the future behaviour and removed the MariaDB branch; that assumption does not hold on 11.8. Restore the isMariaDB flag and broaden the MariaDB assertion to accept either outcome, using the same pattern already in place for Oracle 18. Verified green against MariaDB 11.4 and 11.8 under Connector/J 3.5.4.
mariadb:lts now resolves to 11.8 while our compose was pinned to 11.4, causing drift between local runs and what reviewers / CI pull with the lts tag. Pin to 11.8 explicitly so TestBatchLimitException and friends exercise the current LTS behaviour by default.
MySQL 8.4 defaults users to caching_sha2_password. Connector/J refuses to fetch the server's RSA public key over a non-TLS (useSSL=false) connection unless allowPublicKeyRetrieval=true is set, so every test currently fails with "Public Key Retrieval is not allowed". Add the flag to the test URL so test-mysql-docker works out of the box against the mysql:8.4 image we ship in docker-compose-test-mysql.yml.
|
@cristof I am unable to reproduce |
|
Do we have ASF CI set-up for OpenJPA, so we can run on ASF Infra to see results against current main? |
|
Yes, we have. I've altered former openjpa-pr-17 build config to openjpa-JPA-3.2 and changed default build branch to OPENJPA-2940 (https://ci-builds.apache.org/job/OpenJPA/job/openjpa-JPA-3.2/). |
Alright thx - yeah I thought we might have the other DBMS via ASF CI as well. |
Think we won't see anything meaningful since my changes are not on the ASF Branch (but on my fork); perhaps you need to resync the current ASF OPENNLP-2940 branch with the changes from my fork. |
|
I've pushed a new branch so CI can see your PR (OPENJPA-2940-rzo1). Started a build in ci-builds (still -Ptest-h2-2). |
|
I now have a university vm running Ubuntu 24.04 available and can confirm that PG17/PG18 unit tests are broken running under Linux (works on OSX though). Goging to remote-debug via that VM now because seems a test order thingy ;-) - stay tuned. MariaDB and MySQL look good. For PG17 and PG18, I have 1 failures in the locking tests, which I am currenty looking into. |
…build matrix On PostgreSQL 17+, binding a Java boolean into a SMALLINT column is rejected without an explicit cast. The create-postgresql.sql script declared CUSTMAPPC.FEMALE as SMALLINT, which leaked into the DB when TestSchemaGenerationProperties.testSchemaGenScriptCreate ran before TestEJBCustomMapping (filesystem-order dependent). Change FEMALE to BOOLEAN so the script matches what PostgresDictionary would produce at runtime (bitTypeName="BOOL"). Also add scripts/run-build-matrix.sh, which drives the dockerised mariadb/mysql/pg17/pg18 matrix. It exports TZ=UTC before invoking Maven so the JVM and the docker DB sessions agree on wall clock. This prevents TestEJBQLFunction.testExtractHourFromLocalTime from flaking when the host JVM default TZ differs from the PG session TZ (e.g. Europe/Berlin host vs UTC container).
Hi all, @solomax, @cristof, all
This PR builds on @cristof's JPA 3.2 work, completed with the assistance of generative AI (Claude).
It fully passes the JPA 3.2 TCK (at least on PostgreSQL).
Tests run on Java 21, though there are some local failures - similar to what I see on master, likely an OSX or Java 21 issue rather than something introduced here:
The PR is fairly large, so feel free to cherry-pick whatever is useful. I expect there are concerns and things to address before this is merge-ready.
A number of new tests have been added that mirror TCK behavior. Happy to drop those if they're unwanted.
That said, it was a fun three-week experiment :)