Video in progress

Draw up a plan for migrating a large project from Spring Boot 2 / Hibernate 5 to Spring Boot 3 / Hibernate 6. Where will unexpected breakages happen?

The javax to jakarta move is the mechanical part. The real risk is in Hibernate 6's internal changes: sequence naming, the type system, JPQL semantics, result deduplication and removed APIs. That is why you need SQL-level regression tests and a staged release.

📖 Answer

I split the migration into several layers.

The mechanical part. javax.persistence → jakarta.persistence (an OpenRewrite recipe does this automatically), Java 17, old Hibernate annotations: @JdbcTypeCode or the new @Type(SomeUserType.class) instead of @Type(type = "..."), @TypeDef is removed. The Hibernate Types library (for JSON) moves to a new artifact, or Hibernate 6's own JSON support takes its place.

ID generation. In Hibernate 5, @GeneratedValue(strategy = AUTO) used a shared hibernate_sequence; in 6, it looks for an <entity>_seq per entity and the default is allocationSize=50. Deploy without a migration and you get a startup error or duplicate IDs. There is a temporary hibernate.id.db_structure_naming_strategy=legacy, but I prefer to declare the sequences explicitly.

Query semantics. Hibernate 6 deduplicates the parent entities of a fetch join automatically, so distinct is no longer required, but some code may have relied on the result count. The JPQL parser is stricter: wrong queries that used to "get through" now throw errors. The old Hibernate flavor of the Criteria API is removed.

Type mapping. The default JDBC types for Instant, Duration, enum and boolean columns have changed. ddl-auto=validate will report a lot of errors here.

The process:

  1. A test that records the SQL for all queries (datasource-proxy): we compare the SQL before and after the upgrade.
  2. Go service by service in stages, starting with a small, low-risk one.
  3. Canary deploy, and compare query count and latency metrics.