openrewrite / rewrite-hibernate Goto Github PK
View Code? Open in Web Editor NEWOpenRewrite recipes for Hibernate ORM.
License: Apache License 2.0
OpenRewrite recipes for Hibernate ORM.
License: Apache License 2.0
I am using
I am using the Maven plugin, and my project is a single module project.
mvn org.openrewrite.maven:rewrite-maven-plugin:5.22.0:run -Drewrite.activeRecipes=redacted -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:5.4.0,org.openrewrite.recipe:rewrite-static-analysis:1.3.0 -Drewrite.exclusions=**api**.yaml
@Entity
class A {
@Type(type = "boolean")
private Boolean isAllowed;
}
@Entity
class A {
@Convert(converter = org.hibernate.type.NumericBooleanConverter.class)
private Boolean isAllowed;
}
@Entity
class A {
@Type(boolean.class)
private Boolean isAllowed;
}
It's not necessarily an issue with openrewrite, more that the code left after the recipe ran is non compiling. I think the NumericConverter matches previous behaviour.
There is an existing recipe to migrate to Hibernate 6.2.
This migration handles migration of the dependency io.hypersistence:hypersistence-utils-hibernate-60
to io.hypersistence:hypersistence-utils-hibernate-62
In order to migrate to Hibernate 6.3, a new recipe could handle the migration from io.hypersistence:hypersistence-utils-hibernate-62
to io.hypersistence:hypersistence-utils-hibernate-63
, (see installation guide )
This migration should probably depend on org.openrewrite.hibernate.MigrateToHibernate62
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-62</artifactId>
<version>3.7.3</version>
</dependency>
</dependencies>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-63</artifactId>
<version>3.7.3</version>
</dependency>
</dependencies>
</project>
No
This recipe could later be used in the org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2
recipe
Yes, i could do a PR if that is Ok, this seems like a simple recipe that relies only on org.openrewrite.java.dependencies.ChangeDependency
Original Code:
@typedef(name = "jsonb", typeClass = JsonBinaryType.class)
@type(type = "json")
@column(name = "branding_json", columnDefinition = "json")
private JSONObject branding_json;
After openrewrite Upgrade
@typedef(name = "jsonb", typeClass = JsonBinaryType.class)
@type(jsonb.class) <-- Giving Error
@column(name = "branding_json", columnDefinition = "json")
private JSONObject branding_json;
Excepted Changes
@typedef(name = "jsonb", typeClass = JsonBinaryType.class) <-- This line should be removed
@type(JsonBinaryType.class) <-- This line should be
@column(name = "branding_json", columnDefinition = "json")
private JSONObject branding_json;
Hi the Hibernate 6.1 uprev recipe https://docs.openrewrite.org/recipes/hibernate/typeannotationparameter|TypeAnnotationParameter seems to produce invalid code as part of a Spring Boot 3.2 uprev, given the following input source snippet:
@Type(type = "org.hibernate.type.TextType")
private String description;
produces:
import org.hibernate.type.TextType;
...
@Type(TextType.class)
private String description;
There is no such class TextType
in Hib 6.1. I think in this case the correct action would be just to remove the @Type
annotation completely.
Should use io.hypersistence:hypersistence-utils-hibernate-60
or io.hypersistence:hypersistence-utils-hibernate-62
.
Note: I logged a separate issue for package group changes: #4 since that one is trivial to do and requires fewer things to be considered.
From https://github.com/vladmihalcea/hypersistence-utils#hibernate-5:
@Type(type = "json")
private Map<String, String> properties = new HashMap<>();
From https://github.com/vladmihalcea/hypersistence-utils#hibernate-6:
@Type(JsonType.class)
private Map<String, String> properties = new HashMap<>();
We used to also apply
@TypeDefs({@TypeDef(name = "json", typeClass = JsonStringType.class)})
at the class level. If I read migration guide correctly these annotations should be removed by the recipe.
@LazyCollection is deprecated since Hibernate 6.2 and we should use jakarta.persistence.FetchType instead.
LazyCollectionOption.EXTRA cannot be directly mapped to FetchType. I don't know if automated migration is feasible in that case.
I have implemented a recipe that works well in our project and will open a pull request as a starting point. Please point out all problems and misusages of your API :-)
vladmihalcea/hypersistence-utils was relocated from com.vladmihalcea
group to io.hypersistence
. When customers migrate from Hibernate 5 to 6, they need to update dependency to use a new group and version.
From the migration guide:
io.hypersistence:hypersistence-utils-hibernate-60:3.4.1
,io.hypersistence:hypersistence-utils-hibernate-62:3.4.1
.implementation 'com.vladmihalcea:hibernate-types-52:2.17.1'
implementation 'io.hypersistence:hypersistence-utils-hibernate-60:3.4.1'
Can contribute the week of June 12th-16th '23.
Would you prefer a new recipe or adding it to the existing org.openrewrite.java.migrate.hibernate.MigrateToHibernateDependencies61
recipe?
Hibernate has deprecated the use of the ehcache
2.0 in favor of using jcache
(with the ehcache
3.0 as the underlying implementation)
This recipe should:
hibernate-ehcache
dependency with hibernate-jcache
hibernate.cache.region.factory_class
property with jcache
<property name="hibernate.javax.cache.provider" value="org.ehcache.jsr107.EhcacheCachingProvider"/>
<property name="hibernate.javax.cache.uri" value="file:/META-INF/ehcache.xml"/>
And finally if the ehcache.xml
file does not exist, it should create that file with a defaultCache entry:
<ehcache>
<defaultCache maxEntriesLocalHeap="1000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600">
</defaultCache>
</ehcache>
I am using
Invoking maven plugin as a one-liner to call spring boot upgrade recipes
(any java file which this recipe would touch)
successful changes
the below exception
[DEBUG]
org.openrewrite.internal.RecipeRunException: java.lang.IllegalStateException: Unable to construct Java21Parser.
at org.openrewrite.TreeVisitor.visit (TreeVisitor.java:334)
at org.openrewrite.TreeVisitor.visit (TreeVisitor.java:184)
at org.openrewrite.java.JavaTemplate.apply (JavaTemplate.java:101)
at org.openrewrite.hibernate.MigrateBooleanMappings$1.visitAnnotation (MigrateBooleanMappings.java:100)
at org.openrewrite.hibernate.MigrateBooleanMappings$1.visitAnnotation (MigrateBooleanMappings.java:61)
at org.openrewrite.java.tree.J$Annotation.acceptJava (J.java:235)
at org.openrewrite.java.tree.J.accept (J.java:59)
at org.openrewrite.TreeVisitor.visit (TreeVisitor.java:283)
at org.openrewrite.TreeVisitor.visitAndCast (TreeVisitor.java:366)
at org.openrewrite.java.JavaVisitor.lambda$visitVariableDeclarations$25 (JavaVisitor.java:946)
at org.openrewrite.internal.ListUtils.map (ListUtils.java:176)
at org.openrewrite.java.JavaVisitor.visitVariableDeclarations (JavaVisitor.java:946)
at org.openrewrite.internal.ListUtils.map (ListUtils.java:176)
at org.openrewrite.internal.InMemoryLargeSourceSet.edit (InMemoryLargeSourceSet.java:65)
at org.openrewrite.scheduling.RecipeRunCycle.editSources (RecipeRunCycle.java:133)
at org.openrewrite.RecipeScheduler.runRecipeCycles (RecipeScheduler.java:86)
at org.openrewrite.RecipeScheduler.scheduleRun (RecipeScheduler.java:41)
at org.openrewrite.Recipe.run (Recipe.java:340)
at org.openrewrite.Recipe.run (Recipe.java:336)
at org.openrewrite.Recipe.run (Recipe.java:332)
at org.openrewrite.maven.AbstractRewriteMojo.runRecipe (AbstractRewriteMojo.java:265)
at org.openrewrite.maven.AbstractRewriteMojo.listResults (AbstractRewriteMojo.java:242)
at org.openrewrite.maven.AbstractRewriteRunMojo.execute (AbstractRewriteRunMojo.java:62)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
at java.lang.reflect.Method.invoke (Method.java:580)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: java.lang.IllegalStateException: Unable to construct Java21Parser.
at org.openrewrite.java.Java21Parser$Builder.build (Java21Parser.java:96)
at org.openrewrite.java.Java21Parser$Builder.build (Java21Parser.java:63)
at org.openrewrite.java.internal.template.JavaTemplateParser.compileTemplate (JavaTemplateParser.java:257)
at org.openrewrite.java.internal.template.JavaTemplateParser.lambda$parseAnnotations$10 (JavaTemplateParser.java:218)
at org.openrewrite.java.internal.template.JavaTemplateParser.cache (JavaTemplateParser.java:308)
at org.openrewrite.java.internal.template.JavaTemplateParser.parseAnnotations (JavaTemplateParser.java:215)
at org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitAnnotation (JavaTemplateJavaExtension.java:61)
at org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitAnnotation (JavaTemplateJavaExtension.java:56)
at org.openrewrite.java.tree.J$Annotation.acceptJava (J.java:235)
at org.openrewrite.java.tree.J.accept (J.java:59)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
at java.lang.reflect.Method.invoke (Method.java:580)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: java.lang.IllegalArgumentException: Unable to find runtime dependencies beginning with: 'hibernate-core', 'jakarta.persistence-api', classpath: [redacted]
at org.openrewrite.java.JavaParser.dependenciesFromClasspath (JavaParser.java:108)
at org.openrewrite.java.JavaParser$Builder.resolvedClasspath (JavaParser.java:406)
at org.openrewrite.java.Java21Parser$Builder.build (Java21Parser.java:92)
at org.openrewrite.java.Java21Parser$Builder.build (Java21Parser.java:63)
at org.openrewrite.java.internal.template.JavaTemplateParser.compileTemplate (JavaTemplateParser.java:257)
at org.openrewrite.java.internal.template.JavaTemplateParser.lambda$parseAnnotations$10 (JavaTemplateParser.java:218)
at org.openrewrite.java.internal.template.JavaTemplateParser.cache (JavaTemplateParser.java:308)
at org.openrewrite.java.internal.template.JavaTemplateParser.parseAnnotations (JavaTemplateParser.java:215)
at org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitAnnotation (JavaTemplateJavaExtension.java:61)
at org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitAnnotation (JavaTemplateJavaExtension.java:56)
at org.openrewrite.java.tree.J$Annotation.acceptJava (J.java:235)
at org.openrewrite.java.tree.J.accept (J.java:59)
at org.openrewrite.TreeVisitor.visit (TreeVisitor.java:283)
at org.openrewrite.TreeVisitor.visit (TreeVisitor.java:184)
at org.openrewrite.java.JavaTemplate.apply (JavaTemplate.java:101)
at org.openrewrite.hibernate.MigrateBooleanMappings$1.visitAnnotation (MigrateBooleanMappings.java:100)
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
at java.lang.reflect.Method.invoke (Method.java:580)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
I think the fix is just switching to classpathFromResources
, which I could do, or the original recipe author could do that if they're around and interested (looks like this recipe was committed just last month)
With Hibernate 5 we could map booleans to "T" / "F" by using the "true_false" usertype. Hibernate 6 no longer supports that, but offers an attribute converter as replacement.
class A {
@Type(type = "true_false")
boolean isSomething() {
return isSomething;
}
}
class A {
@Convert(converter = TrueFalseConverter.class)
boolean isSomething() {
return isSomething;
}
}
I have implemented a working recipe. PR is coming up.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.