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
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.
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.
@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 :-)
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
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 just ran the following command:
mvn org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-hibernate:RELEASE -Drewrite.activeRecipes=org.openrewrite.hibernate.MigrateToHibernateDependencies61
The project on which I applied it has a parent-pom and multiple submodule-poms. The parent-pom has a dependencyManagement section where versions are defined using properties. The submodules only list the dependencies without version declaration.
This was before open rewrite:
parent pom:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
submodul pom:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
This after:
parent pom:
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.0.Final</version>
</dependency>
submodul pom:
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.0.Final</version>
</dependency>
OpenRewrite replaced the property in the parent pom (instead of changing it) and added a version tag to the submodul pom although it isnt necessary there
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.
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?
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.