Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Hibernate ORM 6.6 / Search 7.2 / Reactive 2.4 #41359

Merged
merged 8 commits into from
Aug 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.annotations.CompositeType"),
createConstant("org.hibernate.annotations.CompositeTypeRegistration"),
createConstant("org.hibernate.annotations.CompositeTypeRegistrations"),
createConstant("org.hibernate.annotations.ConcreteProxy"),
createConstant("org.hibernate.annotations.ConverterRegistration"),
createConstant("org.hibernate.annotations.ConverterRegistrations"),
createConstant("org.hibernate.annotations.CreationTimestamp"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ void setupLogFilters(BuildProducer<LogCleanupFilterBuildItem> filters) {
filters.produce(new LogCleanupFilterBuildItem("org.hibernate.orm.incubating",
"HHH90006001"));

// Silence DB connection info logging because:
// 1. We don't implement the retrieval of information in QuarkusConnectionProvider
// 2. It's currently being logged even at static init when there is no connection
// See https://hibernate.atlassian.net/browse/HHH-18454
filters.produce(new LogCleanupFilterBuildItem("org.hibernate.orm.connections.pooling",
"HHH10001005"));

//This "deprecation" warning isn't practical for the specific Quarkus needs, as it reminds users they don't need
//to set the 'hibernate.dialect' property, however it's being set by Quarkus buildsteps so they can't avoid it.
//Ignore for now, perhaps remove it upstream however this may make sense for other Hibernate users.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ public void setEmbeddableMapValueWithAnnotation(
}

@Embeddable
@MappedSuperclass
public static class EmbeddableWithAnnotation {
private String text;

Expand Down Expand Up @@ -283,8 +282,29 @@ public void setEmbedded(EmbeddableWithAnnotation embedded) {
}
}

@MappedSuperclass
public static abstract class MappedSuperclassForEmbeddable {
private String text;

protected MappedSuperclassForEmbeddable() {
// For Hibernate ORM only - it will change the property value through reflection
}

public MappedSuperclassForEmbeddable(String text) {
this.text = text;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}
}

@Embeddable
public static class ExtendedEmbeddableWithAnnotation extends EmbeddableWithAnnotation {
public static class ExtendedEmbeddableWithAnnotation extends MappedSuperclassForEmbeddable {
private Integer integer;

protected ExtendedEmbeddableWithAnnotation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public void fetch(Object association) {
delegate.get().fetch(association);
}

@Override
public Object getIdentifier(Object entity) {
return delegate.get().getIdentifier(entity);
}

@Override
public String getTenantIdentifier() {
return delegate.get().getTenantIdentifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@
import org.hibernate.boot.model.process.spi.MetadataBuildingProcess;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.boot.spi.MetadataBuilderContributor;
import org.hibernate.boot.spi.MetadataBuilderImplementor;
import org.hibernate.cache.internal.CollectionCacheInvalidator;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.dialect.spi.DialectFactory;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.EntityManagerMessageLogger;
import org.hibernate.internal.util.StringHelper;
Expand All @@ -60,7 +58,6 @@
import org.hibernate.jpa.boot.spi.TypeContributorList;
import org.hibernate.jpa.internal.util.LogHelper;
import org.hibernate.jpa.internal.util.PersistenceUnitTransactionTypeHelper;
import org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
Expand All @@ -80,7 +77,6 @@
import io.quarkus.hibernate.orm.runtime.recording.PrevalidatedQuarkusMetadata;
import io.quarkus.hibernate.orm.runtime.recording.RecordableBootstrap;
import io.quarkus.hibernate.orm.runtime.recording.RecordedState;
import io.quarkus.hibernate.orm.runtime.service.QuarkusMutableIdentifierGeneratorFactory;
import io.quarkus.hibernate.orm.runtime.service.QuarkusStaticInitDialectFactory;
import io.quarkus.hibernate.orm.runtime.tenant.HibernateMultiTenantConnectionProvider;

Expand Down Expand Up @@ -144,7 +140,6 @@ public FastBootMetadataBuilder(final QuarkusPersistenceUnitDefinition puDefiniti
ssrBuilder.applySettings(buildTimeSettings.getAllSettings());

this.standardServiceRegistry = ssrBuilder.build();
registerIdentifierGenerators(standardServiceRegistry);

this.providedServices = ssrBuilder.getProvidedServices();

Expand Down Expand Up @@ -452,6 +447,7 @@ private PrevalidatedQuarkusMetadata trimBootstrapMetadata(MetadataImpl fullMeta)
fullMeta.getEntityBindingMap(),
fullMeta.getComposites(),
fullMeta.getGenericComponentsMap(),
fullMeta.getEmbeddableDiscriminatorTypesMap(),
fullMeta.getMappedSuperclassMap(),
fullMeta.getCollectionBindingMap(),
fullMeta.getTypeDefinitionMap(),
Expand Down Expand Up @@ -614,32 +610,6 @@ private static void applyTransactionProperties(PersistenceUnitDescriptor persist
}
}

private void registerIdentifierGenerators(StandardServiceRegistry ssr) {
final StrategySelector strategySelector = ssr.getService(StrategySelector.class);

// apply id generators
final Object idGeneratorStrategyProviderSetting = buildTimeSettings
.get(AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER);
if (idGeneratorStrategyProviderSetting != null) {
final IdentifierGeneratorStrategyProvider idGeneratorStrategyProvider = strategySelector
.resolveStrategy(IdentifierGeneratorStrategyProvider.class, idGeneratorStrategyProviderSetting);
final IdentifierGeneratorFactory identifierGeneratorFactory = ssr
.getService(IdentifierGeneratorFactory.class);
if (identifierGeneratorFactory == null) {
throw persistenceException("Application requested custom identifier generator strategies, "
+ "but the MutableIdentifierGeneratorFactory could not be found");
}
if (!(identifierGeneratorFactory instanceof QuarkusMutableIdentifierGeneratorFactory)) {
throw persistenceException(
"Unexpected implementation of IdentifierGeneratorFactory: do not override core components");
}
final QuarkusMutableIdentifierGeneratorFactory qIdGenerator = (QuarkusMutableIdentifierGeneratorFactory) identifierGeneratorFactory;
for (Map.Entry<String, Class<?>> entry : idGeneratorStrategyProvider.getStrategies().entrySet()) {
qIdGenerator.register(entry.getKey(), entry.getValue());
}
}
}

/**
* Greatly simplified copy of
* org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl#populate(org.hibernate.boot.MetadataBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
import org.hibernate.tool.schema.internal.SchemaManagementToolInitiator;

import io.quarkus.hibernate.orm.runtime.cdi.QuarkusManagedBeanRegistryInitiator;
import io.quarkus.hibernate.orm.runtime.customized.QuarkusConnectionProviderInitiator;
import io.quarkus.hibernate.orm.runtime.customized.QuarkusJndiServiceInitiator;
import io.quarkus.hibernate.orm.runtime.customized.QuarkusJtaPlatformInitiator;
import io.quarkus.hibernate.orm.runtime.customized.QuarkusRuntimeProxyFactoryFactory;
import io.quarkus.hibernate.orm.runtime.customized.QuarkusRuntimeProxyFactoryFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.recording.RecordedState;
import io.quarkus.hibernate.orm.runtime.service.CfgXmlAccessServiceInitiatorQuarkus;
import io.quarkus.hibernate.orm.runtime.service.FlatClassLoaderService;
import io.quarkus.hibernate.orm.runtime.service.QuarkusConnectionProviderInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusImportSqlCommandExtractorInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusMutationExecutorServiceInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusRegionFactoryInitiator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
Expand All @@ -30,6 +31,7 @@
import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.metamodel.mapping.DiscriminatorType;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
Expand Down Expand Up @@ -295,6 +297,12 @@ public Component getGenericComponent(Class<?> componentClass) {
return metadata.getGenericComponent(componentClass);
}

@Override
public DiscriminatorType<?> resolveEmbeddableDiscriminatorType(Class<?> embeddableClass,
Supplier<DiscriminatorType<?>> supplier) {
return metadata.resolveEmbeddableDiscriminatorType(embeddableClass, supplier);
}

public Map<String, PersistentClass> getEntityBindingMap() {
return metadata.getEntityBindingMap();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.hibernate.orm.runtime.customized;
package io.quarkus.hibernate.orm.runtime.service;

import java.util.Map;

Expand All @@ -10,6 +10,7 @@
import org.hibernate.service.spi.ServiceRegistryImplementor;

import io.agroal.api.AgroalDataSource;
import io.quarkus.hibernate.orm.runtime.customized.QuarkusConnectionProvider;
import io.quarkus.hibernate.orm.runtime.migration.MultiTenancyStrategy;

public final class QuarkusConnectionProviderInitiator implements StandardServiceInitiator<ConnectionProvider> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@

import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory;
import org.hibernate.service.spi.ServiceRegistryImplementor;

/**
* We need to mimic the standard IdentifierGeneratorFactory but allowing
* to capture which Identifier strategies are being used, so that we can keep a reference to the classed
* needed at runtime.
* Uses a StandardIdentifierGeneratorFactory, but one that doesn't retrieve generators from CDI.
*
* @see IdentifierGeneratorFactory
*/
public final class QuarkusMutableIdentifierGeneratorFactoryInitiator
public final class QuarkusIdentifierGeneratorFactoryInitiator
implements StandardServiceInitiator<IdentifierGeneratorFactory> {

@Override
public IdentifierGeneratorFactory initiateService(final Map configurationValues,
final ServiceRegistryImplementor registry) {
return new QuarkusMutableIdentifierGeneratorFactory(registry);
return new StandardIdentifierGeneratorFactory(registry, true /* ignore bean container */);
}

@Override
Expand Down

This file was deleted.

Loading
Loading