Skip to content

Commit

Permalink
Disallow CDI beans impacting metadata creation
Browse files Browse the repository at this point in the history
Because:

1. We currently disallow this for identifier generators only
   through a custom initializer for the identifier generator
   factory service, but that service is disappearing in Hibernate
   ORM 7.0.0.Beta1, leaving us only the setting `hibernate.cdi.extensions`.
   to disallow CDI for identifier generators -- and anything else
   that impacts metadata creation.
2. This is needed for #40897,
   which will move more of metadata creation to build time -- where CDI
   is just not available.
3. Implementations of affected components needing access to CDI at
   runtime (so not during metadata creation) can still do so by
   calling `Arc.container()` to retrieve the relevant beans.
  • Loading branch information
yrodiere committed Oct 8, 2024
1 parent 62fe0e5 commit 7d00da4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ private RuntimeSettings buildRuntimeSettings(String persistenceUnitName, Recorde
// Allow detection of driver/database capabilities on runtime init (was disabled during static init)
runtimeSettingsBuilder.put("hibernate.boot.allow_jdbc_metadata_access", "true");

// Allow CDI on runtime init (was disabled during static init)
// NOTE: As of Hibernate ORM 7.0.0.Beta1, this does not seem to change anything,
// as all Hibernate-specific "extensions" relying on CDI seem to happen during metadata
// creation, so much before runtime init.
// We're setting this out of an abundance of caution,
// in case a "runtime" Hibernate-specific "extension" is added one day.
runtimeSettingsBuilder.put(AvailableSettings.ALLOW_EXTENSIONS_IN_CDI, "true");

if (!persistenceUnitConfig.unsupportedProperties().isEmpty()) {
log.warnf("Persistence-unit [%s] sets unsupported properties."
+ " These properties may not work correctly, and even if they do,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ private MergedSettings mergeSettings(QuarkusPersistenceUnitDefinition puDefiniti

cfg.put("hibernate.boot.allow_jdbc_metadata_access", "false");

// Disallow CDI during metadata building in anticipation for https://github.com/quarkusio/quarkus/issues/40897
cfg.put(AvailableSettings.ALLOW_EXTENSIONS_IN_CDI, "false");

//This shouldn't be encouraged, but sometimes it's really useful - and it used to be the default
//in Hibernate ORM before the JPA spec would require to change this.
//At this time of transitioning we'll only expose it as a global system property, so to allow usage
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ public List<StandardServiceInitiator<?>> initialInitiatorList() {
serviceInitiators.add(BatchBuilderInitiator.INSTANCE);
serviceInitiators.add(JdbcServicesInitiator.INSTANCE);
serviceInitiators.add(RefCursorSupportInitiator.INSTANCE);

// Custom one!
serviceInitiators.add(new QuarkusIdentifierGeneratorFactoryInitiator());
serviceInitiators.add(StandardIdentifierGeneratorFactoryInitiator.INSTANCE);

serviceInitiators.add(QuarkusJtaPlatformInitiator.INSTANCE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.hibernate.engine.jdbc.internal.JdbcServicesInitiator;
import org.hibernate.engine.jdbc.internal.SqlStatementLoggerInitiator;
import org.hibernate.event.internal.EntityCopyObserverFactoryInitiator;
import org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactoryInitiator;
import org.hibernate.persister.internal.PersisterFactoryInitiator;
import org.hibernate.property.access.internal.PropertyAccessStrategyResolverInitiator;
import org.hibernate.reactive.id.factory.spi.ReactiveIdentifierGeneratorFactoryInitiator;
Expand All @@ -33,7 +34,6 @@
import io.quarkus.hibernate.orm.runtime.customized.BootstrapOnlyProxyFactoryFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.customized.QuarkusJndiServiceInitiator;
import io.quarkus.hibernate.orm.runtime.service.InitialInitiatorListProvider;
import io.quarkus.hibernate.orm.runtime.service.QuarkusIdentifierGeneratorFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusImportSqlCommandExtractorInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusRegionFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusStaticInitDialectFactoryInitiator;
Expand Down Expand Up @@ -95,9 +95,7 @@ public List<StandardServiceInitiator<?>> initialInitiatorList() {
serviceInitiators.add(BatchBuilderInitiator.INSTANCE);
serviceInitiators.add(JdbcServicesInitiator.INSTANCE);
serviceInitiators.add(RefCursorSupportInitiator.INSTANCE);

// Custom one!
serviceInitiators.add(new QuarkusIdentifierGeneratorFactoryInitiator());
serviceInitiators.add(StandardIdentifierGeneratorFactoryInitiator.INSTANCE);

// Custom for Hibernate Reactive:
serviceInitiators.add(NoJtaPlatformInitiator.INSTANCE);
Expand Down

0 comments on commit 7d00da4

Please sign in to comment.