Since 4.0, migrations own the schema. ddl-auto defaults to validate: Hibernate checks that the tables match your mappings but never changes them. A migration tool creates and evolves the schema, and JEHibernate runs it before the SessionFactory is built.
Enable Flyway
Add Flyway to the classpath and put SQL files under db/migration.
-- src/main/resources/db/migration/V001__init.sql
CREATE TABLE warps (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
version INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMP,
updated_at TIMESTAMP
);
With Flyway absent from the classpath, migration is a silent no-op — nothing runs and nothing breaks.
Liquibase is opt-in: set the tool to liquibase and point the location at your changelog.
Keeping Hibernate's auto-DDL instead
If you are not ready for migrations, opt back into Hibernate-managed DDL explicitly:
This is the pragmatic choice for a brand-new embedded database, but on a shared or production database, prefer migrations.
The version column migration
Hibernate 7.2+ maps the optimistic-locking @Version column as NOT NULL. You cannot add it to an already-populated table with ddl-auto=update — the ADD COLUMN fails for existing rows and aborts the whole schema update. Add it with a migration instead.
Adding optimistic locking to a table that never had it:
Upgrading from JEHibernate 4.0.1/4.0.2, where the column was nullable:
A fresh database needs none of this
A schema created by 4.1+ already has version NOT NULL DEFAULT 0. The migration above is only for databases that predate the column.
config.ddlAuto("update"); // Hibernate manages the schema
// or disable the migration step: jehibernate.migration.enabled=false
-- Vxxx__add_version.sql
ALTER TABLE your_table ADD COLUMN version INTEGER NOT NULL DEFAULT 0;
UPDATE your_table SET version = 0 WHERE version IS NULL;
ALTER TABLE your_table ALTER COLUMN version SET NOT NULL; -- PostgreSQL / H2
-- MySQL / MariaDB:
-- ALTER TABLE your_table MODIFY version INTEGER NOT NULL DEFAULT 0;