Migrate to Hibernate 7.0.x
Recipe ID
io.moderne.hibernate.MigrateToHibernate70Artifactio.moderne.recipe:rewrite-hibernateThis recipe will apply changes commonly needed when migrating to Hibernate 7.0.x.
Composite recipeProprietary
Add to your build
Get a download tokenThis recipe is Moderne licensed, so the token must belong to a Moderne customer. It replaces YOUR_DOWNLOAD_TOKEN below.
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("io.moderne.hibernate.MigrateToHibernate70")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("io.moderne.recipe:rewrite-hibernate:0.29.0")
}
Then run
./gradlew rewriteRunUsage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe io.moderne.hibernate.MigrateToHibernate70If the recipe isn’t available locally, install it with:
mod config recipes jar install io.moderne.recipe:rewrite-hibernate:RELEASEDefinition
This recipe runs the following recipes in order.
- Migrate to Hibernate 6.6.x
io.moderne.hibernate.MigrateToHibernate66 - Migrate to Hibernate 7.0.x
org.openrewrite.hibernate.MigrateToHibernate70 - Migrate
jackson-datatype-hibernate6tojackson-datatype-hibernate7io.moderne.hibernate.update70.MigrateJacksonDatatypeHibernate6To7 - Change Gradle or Maven dependency
io.hypersistence:hypersistence-utils-hibernate-63org.openrewrite.java.dependencies.ChangeDependency - Remove a Gradle or Maven dependency
org.openrewrite.java.dependencies.RemoveDependency - Add Gradle or Maven dependency
org.openrewrite.java.dependencies.AddDependency - Remove a Gradle or Maven dependency
org.openrewrite.java.dependencies.RemoveDependency - Remove a Gradle or Maven dependency
org.openrewrite.java.dependencies.RemoveDependency - Remove annotation
@org.hibernate.annotations.GeneratorTypeorg.openrewrite.java.RemoveAnnotation - Remove annotation
@org.hibernate.annotations.LazyToOneorg.openrewrite.java.RemoveAnnotation - Remove annotation
@org.hibernate.annotations.Loaderorg.openrewrite.java.RemoveAnnotation - Remove annotation
@org.hibernate.annotations.Persisterorg.openrewrite.java.RemoveAnnotation - Remove annotation
@org.hibernate.annotations.Proxyorg.openrewrite.java.RemoveAnnotation - Remove annotation
@org.hibernate.annotations.SelectBeforeUpdateorg.openrewrite.java.RemoveAnnotation - Migrate
@JdbcTypeand legacy@Typeto@JdbcTypeCodeio.moderne.hibernate.update70.MigrateJdbcTypeToJdbcTypeCode - Migrate Session interface method calls
io.moderne.hibernate.update70.MigrateSessionInterface - Migrate Session save/update/delete method calls
io.moderne.hibernate.update70.MigrateSessionToDeferToJPA - Migrate NaturalIdLoadAccess method calls
io.moderne.hibernate.update70.MigrateNaturalIdLoadAccess - Migrate NaturalIdMultiLoadAccess method calls
io.moderne.hibernate.update70.MigrateNaturalIdMultiLoadAccess - Replace hibernate annotations with Jakarta variants
io.moderne.hibernate.update70.ReplaceHibernateWithJakartaAnnotations - Migrate to @TargetEmbeddable
io.moderne.hibernate.update70.MigrateToTargetEmbeddable - Migrate implicit cascade=PERSIST for @Id and @MapsId associations
io.moderne.hibernate.update70.AddCascadePersistToIdMappedAssociations - Replace Session.buildLockRequest with LockOptions
io.moderne.hibernate.update70.ReplaceSessionLockRequest - Migrate LockOptions to direct parameters
io.moderne.hibernate.update70.MigrateLockOptionsToDirectParameters - Null safe Transaction#getTimeout()
io.moderne.hibernate.update70.UnboxingTransactionTimeout - Change type
MetamodeltoJpaMetamodelorg.openrewrite.java.ChangeType - Change type
SqmQualifiedJointoSqmJoinorg.openrewrite.java.ChangeType - Change type
org.hibernate.query.BindableTypetoorg.hibernate.type.BindableTypeorg.openrewrite.java.ChangeType - Change type
org.hibernate.query.OutputableTypetoorg.hibernate.type.OutputableTypeorg.openrewrite.java.ChangeType - Change type
org.hibernate.query.spi.BindingContexttoorg.hibernate.type.BindingContextorg.openrewrite.java.ChangeType - Change method name
jakarta.persistence.criteria.Expression as(Class)tocastorg.openrewrite.java.ChangeMethodName - Remove unnecessary cast to
SessionforSessionFactory.createEntityManager()io.moderne.hibernate.update70.RemoveUnnecessaryCastToSession - Migrate
setFlushMode()tosetQueryFlushMode()io.moderne.hibernate.update70.MigrateSetFlushModeToSetQueryFlushMode - Remove leaking of SharedSessionContractImplementor from
org.hibernate.usertype.UserTypeinvocationsio.moderne.hibernate.update70.UserTypeNullSafeGetSharedSessionContractImplementorRecipe - Remove leaking of SharedSessionContractImplementor from
org.hibernate.usertype.UserTypeimplementationsio.moderne.hibernate.update70.UserTypeSharedSessionContractImplementor - Remove leaking of SessionFactoryImplementor from
org.hibernate.usertype.CompositeUserTypeinvocations and implementationsio.moderne.hibernate.update70.CompositeUserTypeSessionFactoryImplementor - Migrate
MetamodelImplementorto Hibernate 7.0io.moderne.hibernate.update70.MigrateMetamodelImplementor - Migrate
Configurable.configure()to useGeneratorCreationContextio.moderne.hibernate.update70.MigrateConfigurableToGeneratorCreationContext - Migrate Hibernate
Integrator#integratemethodio.moderne.hibernate.update70.MigrateIntegratorMethod - Migrate JPQL
trunc()tocast(... as date)io.moderne.hibernate.update70.MigrateJpqlTruncToDateCast - Migrate @Query to @NativeQuery for unsupported JPQL
io.moderne.hibernate.update70.MigrateQueryToNativeQuery - Find native queries with enum parameters requiring SpEL conversion
io.moderne.hibernate.update70.FindNativeQueryRawEnumParameters - Migrate to Hibernate 7 JFR APIs
io.moderne.hibernate.update70.MigrateToHibernate7JFR
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats