From 87d7a32fabd12c9344cfbba72972eddef1968c54 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Tue, 7 Feb 2023 17:20:23 +0100 Subject: [PATCH] [WINDUPRULE-899] Ruleset for hibernate orm 6.9 migration (WIP) --- .../hibernate/hibernate6.windup.xml | 530 ++++++++++++++++++ .../hibernate6/HibernateOrm6TestClass.java | 55 ++ .../hibernate/tests/data/hibernate6/hbm.xml | 13 + .../data/hibernate6/hibernate6.properties | 19 + .../tests/hibernate6.windup.test.xml | 384 +++++++++++++ 5 files changed, 1001 insertions(+) create mode 100644 rules/rules-reviewed/hibernate/hibernate6.windup.xml create mode 100644 rules/rules-reviewed/hibernate/tests/data/hibernate6/HibernateOrm6TestClass.java create mode 100644 rules/rules-reviewed/hibernate/tests/data/hibernate6/hbm.xml create mode 100644 rules/rules-reviewed/hibernate/tests/data/hibernate6/hibernate6.properties create mode 100644 rules/rules-reviewed/hibernate/tests/hibernate6.windup.test.xml diff --git a/rules/rules-reviewed/hibernate/hibernate6.windup.xml b/rules/rules-reviewed/hibernate/hibernate6.windup.xml new file mode 100644 index 000000000..ef29c4f55 --- /dev/null +++ b/rules/rules-reviewed/hibernate/hibernate6.windup.xml @@ -0,0 +1,530 @@ + + + + + + This ruleset provides migration rules to Hibernate ORM 6. + + + + + + + + hibernate + + + + + + + + + + + As part of the Hibernate ORM 6.0 release, mapping annotations have been modernised and made more type-safe. These annotations must be removed. See the User Guide for details about mapping your domain model. + + + + + + + + + + + + + ANNOTATION + + + + + + + As part of the Hibernate ORM 6.0 release, mapping annotations have been modernised and made more type-safe. Annotation attributes accepting types as String have been removed. See the User Guide for details about mapping your domain model. + + + + + + + + + + + + + IMPLEMENTS_TYPE + + + + + Basic mappings are no longer configurable through the BasicType contract. Instead, users configure the different aspects of mapping the basic value to the database. See migration guide for more details. + + + + + + + + + + + The `StandardBasicTypes` class previously exposed `BasicType` instance fields, which now have been replaced with fields of the type `BasicTypeReference`. + + + + + + + + + + + The interface `org.hibernate.type.descriptor.java.JavaTypeDescriptor` must be renamed to `org.hibernate.type.descriptor.java.JavaType`. + + + + + + + + + + + The interface `org.hibernate.type.descriptor.sql.SqlTypeDescriptor` has been renamed to `org.hibernate.type.descriptor.jdbc.JdbcType`. + + + + + + + + + + + The CompositeUserType interface was re-implemented to be able to model user types as proper embeddable types. See the migration guide for more information. + + + + + + + + + + + The configuration property `hibernate.hql.bulk_id_strategy` was changed to `hibernate.query.mutation_strategy` which now refers to classes or objects implementing `org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy`. + + + + + + + + + METHOD_CALL + + + METHOD_CALL + + + + + + + `jakarta.persistence.Query#getResultStream()` and `org.hibernate.query.Query#stream()` no longer return a Stream decorator. In order to close the underlying IO resources, it is now necessary to explicitly call the `Stream#close()` method. + This change makes the Streams returned by Hibernate behave as defined in the JDK Stream documentation, which is quite explicit about the need for an explicit call to close by the user to avoid resource leakages. + + + + + + + + + METHOD_CALL + + + + + The signature of the `Interceptor#onSave` method has been changed to account for the general change in expected identifier type from `Serializable` to `Object`. See migration guide for more information. + + + + + + + + IMPORT + + + + + The contents of the `loader.collection` package were restructured into `loader.ast.spi` and `loader.ast.internal` as well as adapted to the SQM API. + + + + + + + + IMPORT + + + + + The contents of the `loader.custom` package were adapted and moved to `query.sql`. + + + + + + + + + IMPORT + + + IMPORT + + + + + + The contents of `loader.entity` and `loader.plan` were removed + + + + + + + + IMPORT + + + + + The contents of `sql.ordering` were adapted and moved to `metamodel.mapping.ordering.ast`. + + + + + + + + + + + Classes of the sql package that were previously used for building SQL, but aren’t needed anymore, were removed. The SQL generation is now fully handled through the `SqlAstTranslator` which a `Dialect` exposes a factory for. + + + + + + + + + + + + + + In Hibernate 6.0 the support for basic property mappings with multiple columns was removed. The only use case for that was when a `CompositeUserType` was in use, which was reworked to now work on top of components. + + + + + + + + IMPORT + + + + + The legacy Hibernate Criteria API which was deprecated back in Hibernate 5.x and removed in 6.0. Usually, all queries using the legacy API can be modeled with the JPA Criteria API. In some cases it is necessary to use the Hibernate JPA Criteria extensions. + + + + + + + + METHOD_CALL + + + + + The Query#iterate() method has been removed. See link for alternatives. + + + + + + + + + ANNOTATION + + + + + + + + Using `NativeQuery` to call SQL functions and procedures is no longer supported. `org.hibernate.procedure.ProcedureCall` or `jakarta.persistence.StoredProcedureQuery` should be used instead. `@NamedNativeQuery` references defining execution of procedure or functions should be migrated to use `@NamedStoredProcedureQuery` instead. + + + + + + + + + + + + The fetch all properties clause was removed from the HQL language without a replacement. See link for replacement info. + + + + + + + + + + + Hibernate no longer provides built-in support for integrating itself with JMX environments. + + + + + + + + + + + Hibernate no longer provides built-in support for integrating itself with JACC environments. + + + + + + + + + + + + + + + + These properties are deprecated: use `hibernate.classLoaders` instead. + + + + + + + + + + + This property has been removed: use `jakarta.persistence.create-database-schemas` or `hibernate.hbm2ddl.create_namespaces` instead + + + + + + + + + + + + + + This property has been removed: please use `hibernate.jpa.metamodel.population` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.cfg_xml_file` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.orm_xml_files` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.hbm_xml_files` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.loaded_classes` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.persistenceUnitName` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.discard_pc_on_close` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.session_factory_name` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.session_factory_observer` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.identifier_generator_strategy_provider` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.classcache` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.collectioncache` instead + + + + + + + + + + + + + This property has been removed: please use `hibernate.event` instead + + + + + + + + + + + + As of Hibernate 6.0, some dialect classes that are maintained by vendors or individuals, as opposed to the Hibernate team. have moved to a separate Maven artifact: `org.hibernate.orm:hibernate-community-dialects`. + + + + + + + + + \ No newline at end of file diff --git a/rules/rules-reviewed/hibernate/tests/data/hibernate6/HibernateOrm6TestClass.java b/rules/rules-reviewed/hibernate/tests/data/hibernate6/HibernateOrm6TestClass.java new file mode 100644 index 000000000..7977fc17b --- /dev/null +++ b/rules/rules-reviewed/hibernate/tests/data/hibernate6/HibernateOrm6TestClass.java @@ -0,0 +1,55 @@ +import org.hibernate.annotations.AnyMetaDef; +import org.hibernate.annotations.NamedNativeQuery; +import org.hibernate.annotations.ParamDef; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; +import org.hibernate.query.Query; +import org.hibernate.type.BasicType; +import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.Type; +import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; +import org.hibernate.usertype.CompositeUserType; + +import org.hibernate.loader.collection.BasicCollectionLoader; +import org.hibernate.loader.custom.CustomLoader; +import org.hibernate.loader.entity.CascadeEntityJoinWalker; +import org.hibernate.loader.plan.build.spi.ExpandingQuerySpace; +import org.hibernate.sql.ordering.antlr.ColumnMapper; + +import org.hibernate.jmx.internal.DisabledJmxServiceImpl; + +import org.hibernate.criterion.Criterion; + +@NamedNativeQuery(callable = true, name = "name", query = "query") +public class HibernateOrm6TestClass implements BasicType { + @AnyMetaDef(metaType = "type") + String hey; + + @ParamDef(name = "name", type = "type") + String param; + + StandardBasicTypes types; + + JavaTypeDescriptor javaTypeDescriptor; + + SqlTypeDescriptor sqlTypeDescriptor; + + CompositeUserType compositeUserType; + + public static void main(String[] args) { + org.hibernate.query.Query q; + q.stream(); + jakarta.persistence.Query q2; + q2.getResultStream(); + + org.hibernate.secure.spi.JaccIntegrator integrator; + + org.hibernate.Interceptor interceptor; + interceptor.onSave(new Object(), new Object(), new Object[]{}, new String[]{}, new Type[]{}); + + org.hibernate.sql.ANSICaseFragment fragment; + + org.hibernate.Query q3; + q3.iterate(); + } + +} diff --git a/rules/rules-reviewed/hibernate/tests/data/hibernate6/hbm.xml b/rules/rules-reviewed/hibernate/tests/data/hibernate6/hbm.xml new file mode 100644 index 000000000..3b6db47ea --- /dev/null +++ b/rules/rules-reviewed/hibernate/tests/data/hibernate6/hbm.xml @@ -0,0 +1,13 @@ + + + + + + + + + + SELECT x FROM persons fetch all properties + + + \ No newline at end of file diff --git a/rules/rules-reviewed/hibernate/tests/data/hibernate6/hibernate6.properties b/rules/rules-reviewed/hibernate/tests/data/hibernate6/hibernate6.properties new file mode 100644 index 000000000..ed041e98a --- /dev/null +++ b/rules/rules-reviewed/hibernate/tests/data/hibernate6/hibernate6.properties @@ -0,0 +1,19 @@ +hibernate.ejb.metamodel.population=value +hibernate.ejb.cfgfile=value +hibernate.ejb.xml_files=value +hibernate.hbmxml.files=value +hibernate.ejb.loaded.classes=value +hibernate.ejb.persistenceUnitName=value +hibernate.ejb.discard_pc_on_close=value +hibernate.ejb.entitymanager_factory_name=value +hibernate.ejb.session_factory_observer=value +hibernate.ejb.identifier_generator_strategy_provider=value +hibernate.ejb.classcache=value +hibernate.ejb.collectioncache=value +hibernate.ejb.event=value +hibernate.hql.bulk_id_strategy=value +hibernate.classLoader.application=value +hibernate.classLoader.resources=value +hibernate.classLoader.hibernate=value +hibernate.classLoader.environment=value +hibernate.hbm2dll.create_namespaces=value diff --git a/rules/rules-reviewed/hibernate/tests/hibernate6.windup.test.xml b/rules/rules-reviewed/hibernate/tests/hibernate6.windup.test.xml new file mode 100644 index 000000000..2fb9b61a7 --- /dev/null +++ b/rules/rules-reviewed/hibernate/tests/hibernate6.windup.test.xml @@ -0,0 +1,384 @@ + + + + data/hibernate6 + ../ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +