All frameworks
ANJUNAR / OPEN SOURCE

Hibernate DDL Manager

Controlled schema evolution from Hibernate metadata.

01

The idea

A Scala 3 framework that compares Hibernate mappings with the database before SessionFactory startup. Stable schema IDs let it recognize renames and make potentially destructive changes explicit.

02

What it does.

01

Schema comparison

Derive a change plan from Hibernate metadata and the current database.

02

Rename detection

Stable IDs distinguish a rename from a drop and an add.

03

Explicit approval

Changes outside the supported scope are refused instead of guessed.

03

Installation

Add to your project
libraryDependencies += "com.anjunar.hibernateddl" %% "schema-integration" % "1.0.0"

Package: com.anjunar.hibernateddl:schema-integration

04

Start building.

Add schema-integration and assign stable @SchemaId values to managed entities and fields.

Stable IDs make renames visible

The column name can change while its schema ID stays the same. The planned migration becomes a rename instead of a drop and add.

Source code
@Entity
@SchemaId("7f3a9c21")
@Table(name = "customer")
class Customer:
  @Id @SchemaId("0a1b2c3d")
  var id: java.lang.Long = uninitialized

  @SchemaId("f34e45b6")
  @Column(name = "nick_name")
  var nickName: String = uninitialized

// Rename nick_name to alias; keep its @SchemaId.
// Planned SQL: ALTER TABLE "public"."customer"
//              RENAME COLUMN "nick_name" TO "alias";

Preview before startup

Preview the exact plan without changing the database, then run the migration before creating the SessionFactory.

Source code
val metadata = MetadataSources(registry)
  .addAnnotatedClass(classOf[Customer])
  .buildMetadata()

val report = HibernateSchemaMigration.preview(
  metadata, dataSource,
  previewOptions = PreviewOptions(dataChecks = DataChecks.Existence)
)
println(PreviewRendering.text(report))

HibernateSchemaMigration.migrate(metadata, dataSource)
val sessionFactory = metadata.buildSessionFactory()
05

By design.

The integration runs before SessionFactory creation. It records schema history and applies only supported PostgreSQL changes.

Your next step

Make it part of your stack.

Built carefully with Scala JS UI.Imprint