Entity readers¶
With Hibernate 4 or newer in your project, Migrax asks your Hibernate version itself for the mapping, without connecting to a database. The generated schema is therefore exactly what your application expects: names, types, join tables, element collections, inheritance and sequences.
Compatibility¶
Every version below is tested on each change to Migrax. A fixture project with identity and
sequence ids, enums, embedded types, element collections (sets, ordered lists, embeddables),
one-to-many, many-to-one and many-to-many relationships, single-table inheritance and
@Version is generated, migrated and verified. That same Hibernate version then validates the
schema, and the rollback scripts are tested.
| Hibernate | Entities | Typical frameworks | Status |
|---|---|---|---|
| 7.0 – 7.4 | jakarta.persistence |
Spring Boot 4, recent Quarkus 3 releases, Micronaut 5 | Supported |
| 6.3 – 6.6 | jakarta.persistence |
Spring Boot 3.2 to 3.5, Quarkus 3, Micronaut 4, Helidon 4 | Supported |
| 6.0 – 6.2 | jakarta.persistence |
Spring Boot 3.0 and 3.1, early Quarkus 3 releases | Supported |
| 5.3 – 5.6 | javax.persistence |
Spring Boot 2.1 to 2.7 | Supported |
| 5.0 – 5.2 | javax.persistence |
Spring Boot 1.4 to 2.0 | Supported (needs JAXB, see below) |
| 4.0 – 4.3 | javax.persistence |
Spring Boot 1.0 to 1.3, JBoss AS 7, JBoss EAP 6, WildFly 8 and 9 | Supported |
| before 4.0 | javax.persistence |
older applications | Annotation scanning only |
Tested patch versions: 4.0.1, 4.1.12, 4.2.21, 4.3.11, 5.0.12, 5.1.17, 5.2.18, 5.3.36, 5.4.33, 5.5.9, 5.6.15, 6.0.2, 6.1.7, 6.2.52, 6.3.2, 6.4.10, 6.5.3, 6.6.58, 7.0.10, 7.1.36, 7.2.25, 7.3.13 and 7.4.12.
Hibernate 5.0 to 5.2 need JAXB
These versions use JAXB, which Java 11 and newer no longer include. Migrax runs on Java 17,
so add it to your project as your application on Java 11 or newer needs anyway:
javax.xml.bind:jaxb-api and org.glassfish.jaxb:jaxb-runtime (2.3.x). Without it,
Migrax reads your entities from their annotations and verify compares the schema itself,
and both say that JAXB is missing.
Hibernate 4
The migrations follow Hibernate 4's own rules: its names (Hibernate 4 keeps names as
written, such as createdAt, unless the application sets a naming strategy) and its id
generators: a plain @GeneratedValue is an identity column on H2, MySQL, MariaDB and SQL
Server and the shared hibernate_sequence on PostgreSQL and Oracle, and sequences count
up by 1 unless hibernate.id.new_generator_mappings is on. Spring Boot 1's
spring.jpa.hibernate.naming-strategy is read like hibernate.ejb.naming_strategy.
Hibernate 4.0 to 4.2 implement JPA 2.0, so @Table(indexes = ...) needs 4.3. Hibernate 4.0
and 4.1 have no sequences on SQL Server (their newest SQL Server dialect is for 2008), so
entities there use identity columns, as the application itself needs.
EclipseLink¶
When your project uses EclipseLink instead of Hibernate, Migrax asks your EclipseLink for
its mapping, again without connecting to a database. The migrations then have the names
EclipseLink uses (its default names such as ID and Customer_SCORES, written in lower case
except where the database's table names are case-sensitive, as on MySQL), and what its id
strategies need:
GenerationType.IDENTITY: an identity column.GenerationType.SEQUENCE: a database sequence, started the way EclipseLink expects; on databases without sequences (MySQL), an identity column, as EclipseLink uses there.- A plain
@GeneratedValue(orTABLE): EclipseLink'sSEQUENCEtable and its row for each generator.
Tested versions: 2.7.15 (javax.persistence), 3.0.4 and 4.0.4 (jakarta.persistence). The
same fixture project is generated, migrated and verified, and then EclipseLink itself saves and
reads every kind of entity against the migrated database. EclipseLink has no schema validation,
so verify compares the schema with the mapping itself.
OpenJPA¶
Projects that use OpenJPA (the JPA provider of Apache TomEE) are read through your OpenJPA's
own mapping, also without a database. The migrations get OpenJPA's names (the class and field
names as written, such as Tag and createdAt, in lower case except where the database's table
names are case-sensitive), the indexes OpenJPA puts on foreign keys, and its id strategies:
identity columns, database sequences, and OPENJPA_SEQUENCE_TABLE for a plain
@GeneratedValue (OpenJPA adds its row itself).
Tested versions: 3.2.2 (javax.persistence) and 4.1.1 (jakarta.persistence), with OpenJPA
saving and reading every kind of entity against the migrated database, as for EclipseLink.
OpenJPA has no sequences on MySQL and MariaDB: use GenerationType.IDENTITY there.
Spring Data JDBC¶
New in Migrax 0.17.0.
Projects that use Spring Data JDBC instead of JPA are read through your Spring Data JDBC's
own mapping, without a database. Migrax finds the aggregate roots under the entity package: the
classes with @Table (org.springframework.data.relational.core.mapping.Table) and the types
of your repositories, so a class without annotations counts once a repository uses it. The
migrations get the tables Spring Data JDBC reads and writes:
- Names from Spring Data JDBC's naming (
createdAtbecomescreated_at), or as written in@Table,@Columnand@MappedCollection(idColumn, keyColumn). - A child entity (a
Set,List,Mapor single property of another entity) gets its own table with the back-reference column to its parent, the key column for aListindex or aMapkey, and a foreign key to the parent. A reference to another aggregate (AggregateReference) is a plain column, without a foreign key, because the two are saved and deleted on their own. - Embedded values (
@Embedded) become columns of the same table, with their prefix. - A
LongorIntegerid is an identity column, as Spring Data JDBC lets the database create it;@Sequence(Spring Data JDBC 3.5 and newer) creates the sequence instead. - Enums are stored by name,
byte[]as binary data. Only ids and primitive types (int,boolean) areNOT NULL: Spring Data JDBC has no annotation that says a column can't be empty.
Spring Data JDBC puts every name in quotes, and a quoted name keeps its letter case. So where
an unquoted name would get another case, Migrax quotes the name too: a name you write in lower
case, such as @Table("customers"), on H2, Oracle, HSQLDB and Derby
(CREATE TABLE "customers"), and a name with capitals, such as @Column("Nick"), on
PostgreSQL. Names Spring Data JDBC derives itself, and every name on MySQL and SQL Server, are
written as usual.
Spring Data JDBC is used when the entity package has no JPA entities; with
--extractor spring-data-jdbc it is used in any case. migrax doctor shows the version it
found. The Spring Boot starter applies the migrations at startup without JPA too.
Tested versions: Spring Data JDBC 3.0, 3.2, 3.5 and 4.1 (Spring Boot 3.0.13, 3.2.12, 3.5.16 and 4.1.1), on H2 and PostgreSQL. A fixture with every kind of aggregate is generated, migrated and verified, and then Spring Data JDBC itself saves, loads, updates and deletes it against the migrated database; after a new field, the second migration is checked the same way.
Not read: a collection of simple values (List<String>), which Spring Data JDBC stores as a
database array (Migrax warns and leaves the column out), and a naming strategy or quoting
setting your application changes in its own beans: write such names in the annotations.
Micronaut Data¶
New in Migrax 0.17.0.
Projects that use Micronaut Data JDBC or R2DBC (@MappedEntity) are read through the mapping
your Micronaut Data's annotation processor compiled into the classes, without a database
or a running application. The migrations follow Micronaut Data's own rules:
- Names from the entity's naming strategy (
fullNamebecomesfull_name), or as written in@MappedEntity,@MappedPropertyand@JoinTable. Micronaut Data puts names in quotes, so on PostgreSQL a name with capitals (@MappedEntity("Publisher")) is created in quotes too. NOT NULLfor every property that isn't@Nullable, as Micronaut Data expects.- A many-to-one or one-to-one reference becomes its
_idcolumn with a foreign key. A many-to-many relation (or a one-to-many withoutmappedBy) gets its join table, without foreign keys: Micronaut Data deletes an entity without its join table rows, so a foreign key there would make deletes fail. - Generated ids as Micronaut Data makes them: an identity column, a sequence
(
GeneratedValue.Type.SEQUENCE, named<table>_seqorref, and every generated id on Oracle), or a UUID the database fills in (on MySQL, MariaDB and TiDB Micronaut Data sends the UUID itself). UUIDs arevarchar(36)on MySQL, MariaDB, TiDB and Oracle, as Micronaut Data stores them there. - Embedded values (
@Embeddable) become columns of the same table, named as your version names them (Micronaut Data 5 leaves out the prefix). @MappedProperty(definition = ...)is used as written;@Size(max)and JPA's@Column(length, precision, scale)set sizes.
Micronaut Data is used when the entity package has @MappedEntity classes and no JPA entities;
with --extractor micronaut-data it is used in any case. Entities written with JPA annotations
(micronaut-data-hibernate-jpa) are read as JPA entities, as before.
Tested versions: Micronaut Data 4.0, 4.14 and 5.2 (Micronaut 4.0.6, 4.10.22 and 5.2.3), on H2 and PostgreSQL. A fixture with every kind of entity is generated, migrated and verified, and then Micronaut Data itself saves, loads, updates and deletes it against the migrated database; after a new field, the second migration is checked the same way.
Not read: array properties (String[], PostgreSQL arrays) and other types without a
@MappedProperty(definition): Migrax warns and leaves the column out. Micronaut 5 projects need
Migrax running on Java 25.
Without Hibernate, EclipseLink or OpenJPA, or before Hibernate 4¶
Migrax then scans the JPA annotations and applies Hibernate 6's rules. That covers the common
mappings, but types and sequence names can differ from older Hibernate versions (they use one
shared hibernate_sequence, for example). migrax doctor warns when this applies. Check
generated migrations carefully and run migrax verify.
Choosing the reader¶
--extractor |
Behavior |
|---|---|
auto (default) |
Spring Data JDBC's or Micronaut Data's mapping when the package has no JPA entities, else Hibernate's mapping when possible, else EclipseLink's or OpenJPA's, else annotation scanning |
hibernate |
Hibernate's mapping only; fails with the reason if it can't be used |
eclipselink |
EclipseLink's mapping only; fails with the reason if it can't be used |
openjpa |
OpenJPA's mapping only; fails with the reason if it can't be used |
spring-data-jdbc |
Spring Data JDBC's mapping only; fails with the reason if it can't be used |
micronaut-data |
Micronaut Data's mapping only; fails with the reason if it can't be used |
annotations |
Annotation scanning only |
migrax doctor shows which reader is used. migrax inspect prints the schema it read.