From 6cc26fdb2cf79961cc7a904204848ce05c36f9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 20 Jan 2025 10:39:39 +0100 Subject: [PATCH] Restore condition for registering Validator-related classes for reflection in Hibernate ORM extension --- .../orm/deployment/HibernateOrmProcessor.java | 16 ++++++++++------ .../PersistenceUnitDescriptorBuildItem.java | 9 ++++++++- .../runtime/boot/FastBootMetadataBuilder.java | 6 +++++- .../boot/QuarkusPersistenceUnitDefinition.java | 7 +++++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java index f40a528c1d42f..680449827e0e4 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java @@ -241,12 +241,16 @@ AdditionalIndexedClassesBuildItem addPersistenceUnitAnnotationToIndex() { @BuildStep public void enrollBeanValidationTypeSafeActivatorForReflection(Capabilities capabilities, BuildProducer reflectiveClasses) { - // Accessed in org.hibernate.boot.beanvalidation.BeanValidationIntegrator.loadTypeSafeActivatorClass - reflectiveClasses.produce(ReflectiveClassBuildItem.builder("org.hibernate.boot.beanvalidation.TypeSafeActivator") - .methods().fields().build()); - // Accessed in org.hibernate.boot.beanvalidation.BeanValidationIntegrator.isBeanValidationApiAvailable - reflectiveClasses.produce(ReflectiveClassBuildItem.builder(BeanValidationIntegrator.JAKARTA_BV_CHECK_CLASS) - .constructors(false).build()); + if (capabilities.isPresent(Capability.HIBERNATE_VALIDATOR)) { + // BeanValidationIntegrator is only added if this capability is present, see FastBootMetadataBuilder + + // Accessed in org.hibernate.boot.beanvalidation.BeanValidationIntegrator.loadTypeSafeActivatorClass + reflectiveClasses.produce(ReflectiveClassBuildItem.builder("org.hibernate.boot.beanvalidation.TypeSafeActivator") + .methods().fields().build()); + // Accessed in org.hibernate.boot.beanvalidation.BeanValidationIntegrator.isBeanValidationApiAvailable + reflectiveClasses.produce(ReflectiveClassBuildItem.builder(BeanValidationIntegrator.JAKARTA_BV_CHECK_CLASS) + .constructors(false).build()); + } } @BuildStep diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/PersistenceUnitDescriptorBuildItem.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/PersistenceUnitDescriptorBuildItem.java index 4fe0aec17e4df..fe343c0f63348 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/PersistenceUnitDescriptorBuildItem.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/PersistenceUnitDescriptorBuildItem.java @@ -29,6 +29,7 @@ public final class PersistenceUnitDescriptorBuildItem extends MultiBuildItem { private final List xmlMappings; private final boolean isReactive; private final boolean fromPersistenceXml; + private final boolean isHibernateValidatorPresent; private final Optional jsonMapper; private final Optional xmlMapper; @@ -43,6 +44,7 @@ public PersistenceUnitDescriptorBuildItem(QuarkusPersistenceUnitDescriptor descr this.xmlMappings = xmlMappings; this.isReactive = isReactive; this.fromPersistenceXml = fromPersistenceXml; + this.isHibernateValidatorPresent = capabilities.isPresent(Capability.HIBERNATE_VALIDATOR); this.jsonMapper = json(capabilities); this.xmlMapper = xml(capabilities); } @@ -79,10 +81,15 @@ public boolean isFromPersistenceXml() { return fromPersistenceXml; } + public boolean isHibernateValidatorPresent() { + return isHibernateValidatorPresent; + } + public QuarkusPersistenceUnitDefinition asOutputPersistenceUnitDefinition( List integrationStaticDescriptors) { return new QuarkusPersistenceUnitDefinition(descriptor, config, - xmlMappings, isReactive, fromPersistenceXml, jsonMapper, xmlMapper, integrationStaticDescriptors); + xmlMappings, isReactive, fromPersistenceXml, isHibernateValidatorPresent, + jsonMapper, xmlMapper, integrationStaticDescriptors); } private Optional json(Capabilities capabilities) { diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java index 520c8c4d25f5a..003c9c8053f4b 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java @@ -111,6 +111,7 @@ public class FastBootMetadataBuilder { private final MultiTenancyStrategy multiTenancyStrategy; private final boolean isReactive; private final boolean fromPersistenceXml; + private final boolean isHibernateValidatorPresent; private final List integrationStaticDescriptors; @SuppressWarnings("unchecked") @@ -119,6 +120,7 @@ public FastBootMetadataBuilder(final QuarkusPersistenceUnitDefinition puDefiniti this.persistenceUnit = puDefinition.getPersistenceUnitDescriptor(); this.isReactive = puDefinition.isReactive(); this.fromPersistenceXml = puDefinition.isFromPersistenceXml(); + this.isHibernateValidatorPresent = puDefinition.isHibernateValidatorPresent(); this.additionalIntegrators = additionalIntegrators; this.preGeneratedProxies = preGeneratedProxies; this.integrationStaticDescriptors = puDefinition.getIntegrationStaticDescriptors(); @@ -476,7 +478,9 @@ private Dialect extractDialect() { private Collection getIntegrators() { LinkedHashSet integrators = new LinkedHashSet<>(); - integrators.add(new BeanValidationIntegrator()); + if (isHibernateValidatorPresent) { + integrators.add(new BeanValidationIntegrator()); + } integrators.add(new CollectionCacheInvalidator()); for (Class integratorClass : additionalIntegrators) { diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/QuarkusPersistenceUnitDefinition.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/QuarkusPersistenceUnitDefinition.java index 33ac46deeb80d..c7cff5464c9b4 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/QuarkusPersistenceUnitDefinition.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/QuarkusPersistenceUnitDefinition.java @@ -21,6 +21,7 @@ public final class QuarkusPersistenceUnitDefinition { private final List xmlMappings; private final boolean isReactive; private final boolean fromPersistenceXml; + private final boolean isHibernateValidatorPresent; private final Optional jsonMapperCreator; private final Optional xmlMapperCreator; private final List integrationStaticDescriptors; @@ -31,6 +32,7 @@ public QuarkusPersistenceUnitDefinition(QuarkusPersistenceUnitDescriptor persist List xmlMappings, boolean reactive, boolean fromPersistenceXml, + boolean isHibernateValidatorPresent, Optional jsonMapperCreator, Optional xmlMapperCreator, List integrationStaticDescriptors) { @@ -41,6 +43,7 @@ public QuarkusPersistenceUnitDefinition(QuarkusPersistenceUnitDescriptor persist this.xmlMappings = xmlMappings; this.isReactive = reactive; this.fromPersistenceXml = fromPersistenceXml; + this.isHibernateValidatorPresent = isHibernateValidatorPresent; this.jsonMapperCreator = jsonMapperCreator; this.xmlMapperCreator = xmlMapperCreator; this.integrationStaticDescriptors = integrationStaticDescriptors; @@ -71,6 +74,10 @@ public boolean isFromPersistenceXml() { return fromPersistenceXml; } + public boolean isHibernateValidatorPresent() { + return isHibernateValidatorPresent; + } + public Optional getJsonMapperCreator() { return jsonMapperCreator; }