Skip to content

Commit

Permalink
Restore condition for registering Validator-related classes for refle…
Browse files Browse the repository at this point in the history
…ction in Hibernate ORM extension
  • Loading branch information
yrodiere committed Jan 20, 2025
1 parent ebab4ce commit 6cc26fd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,16 @@ AdditionalIndexedClassesBuildItem addPersistenceUnitAnnotationToIndex() {
@BuildStep
public void enrollBeanValidationTypeSafeActivatorForReflection(Capabilities capabilities,
BuildProducer<ReflectiveClassBuildItem> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public final class PersistenceUnitDescriptorBuildItem extends MultiBuildItem {
private final List<RecordableXmlMapping> xmlMappings;
private final boolean isReactive;
private final boolean fromPersistenceXml;
private final boolean isHibernateValidatorPresent;
private final Optional<FormatMapperKind> jsonMapper;
private final Optional<FormatMapperKind> xmlMapper;

Expand All @@ -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);
}
Expand Down Expand Up @@ -79,10 +81,15 @@ public boolean isFromPersistenceXml() {
return fromPersistenceXml;
}

public boolean isHibernateValidatorPresent() {
return isHibernateValidatorPresent;
}

public QuarkusPersistenceUnitDefinition asOutputPersistenceUnitDefinition(
List<HibernateOrmIntegrationStaticDescriptor> integrationStaticDescriptors) {
return new QuarkusPersistenceUnitDefinition(descriptor, config,
xmlMappings, isReactive, fromPersistenceXml, jsonMapper, xmlMapper, integrationStaticDescriptors);
xmlMappings, isReactive, fromPersistenceXml, isHibernateValidatorPresent,
jsonMapper, xmlMapper, integrationStaticDescriptors);
}

private Optional<FormatMapperKind> json(Capabilities capabilities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HibernateOrmIntegrationStaticDescriptor> integrationStaticDescriptors;

@SuppressWarnings("unchecked")
Expand All @@ -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();
Expand Down Expand Up @@ -476,7 +478,9 @@ private Dialect extractDialect() {

private Collection<Integrator> getIntegrators() {
LinkedHashSet<Integrator> integrators = new LinkedHashSet<>();
integrators.add(new BeanValidationIntegrator());
if (isHibernateValidatorPresent) {
integrators.add(new BeanValidationIntegrator());
}
integrators.add(new CollectionCacheInvalidator());

for (Class<? extends Integrator> integratorClass : additionalIntegrators) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public final class QuarkusPersistenceUnitDefinition {
private final List<RecordableXmlMapping> xmlMappings;
private final boolean isReactive;
private final boolean fromPersistenceXml;
private final boolean isHibernateValidatorPresent;
private final Optional<FormatMapperKind> jsonMapperCreator;
private final Optional<FormatMapperKind> xmlMapperCreator;
private final List<HibernateOrmIntegrationStaticDescriptor> integrationStaticDescriptors;
Expand All @@ -31,6 +32,7 @@ public QuarkusPersistenceUnitDefinition(QuarkusPersistenceUnitDescriptor persist
List<RecordableXmlMapping> xmlMappings,
boolean reactive,
boolean fromPersistenceXml,
boolean isHibernateValidatorPresent,
Optional<FormatMapperKind> jsonMapperCreator,
Optional<FormatMapperKind> xmlMapperCreator,
List<HibernateOrmIntegrationStaticDescriptor> integrationStaticDescriptors) {
Expand All @@ -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;
Expand Down Expand Up @@ -71,6 +74,10 @@ public boolean isFromPersistenceXml() {
return fromPersistenceXml;
}

public boolean isHibernateValidatorPresent() {
return isHibernateValidatorPresent;
}

public Optional<FormatMapperKind> getJsonMapperCreator() {
return jsonMapperCreator;
}
Expand Down

0 comments on commit 6cc26fd

Please sign in to comment.