Jakarta Persistence schema generation and SQL scripts
The jakarta.persistence.schema-generation.* properties are now honored as described by the specification: scripts.action is mapped to schema tool actions on its own (previously only database.action was considered) and scripts are generated or executed when the EntityManagerFactory is created rather than lazily with the first EntityManager; explicit create-source/drop-source values are respected; java.io.Writer/Reader targets and sources, file: URIs and absolute paths are accepted.
When Writer/Reader objects are supplied, the corresponding keys are removed from the caller’s property map, so the map must be mutable. Persistence.generateSchema() defaults database.action=create only if neither database.action nor scripts.action is given.
A table dropped by an executed drop script is skipped by the next buildSchema/add run in the same JVM (once by default; until an EntityManagerFactory with schema-generation properties starts when openjpa.SpecCompliantSchemaGeneration=true) instead of being silently re-created.
SQL scripts (create, drop and load scripts) are now parsed as ;-terminated statements that may span several lines, with --, // and /* … */ comments stripped (string literals are not recognized). Previously every line was one statement.
Errors in scripts executed through schema generation are logged as warnings on the openjpa.jdbc.Schema channel instead of failing start-up.
Terminate every statement with ; and check the log for script errors.
Related SchemaTool changes: table truncation continues after failing statements, dropping the last column of a table drops the whole table, and the new DBDictionary.isDroppable(Sequence) hook excludes system sequences.
Two options were added. openjpa.SpecCompliantSchemaGeneration=true (also available as openjpa.Compatibility=SpecCompliantSchemaGeneration=true, default false) enables strict Jakarta Persistence semantics: a schema-generation configuration that resolves to no action (for example database.action=none) also disables openjpa.jdbc.SynchronizeMappings, @MapsId foreign key columns are named <relation>_<targetPk>, and on PostgreSQL identifiers are never quoted.
Do not enable it on existing databases created by earlier releases.
The option openjpa.jdbc.SyncMappingsExcludeTypes=a.B;c.D (or SynchronizeMappings=buildSchema(ExcludeTypes=a.B;c.D)) excludes entity classes from schema synchronization and drops their existing tables; only list entities whose tables may be destroyed.
See Runtime Forward Mapping and SQL Scripting.