Skip to content

Commit

Permalink
Upgrade to Hibernate ORM 7.0.0.Alpha3
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Jun 25, 2024
1 parent ede4448 commit af4a80c
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 101 deletions.
7 changes: 4 additions & 3 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<jakarta.json-api.version>2.1.3</jakarta.json-api.version>
<jakarta.json.bind-api.version>3.0.1</jakarta.json.bind-api.version>
<jakarta.mail.version>2.0.1</jakarta.mail.version>
<jakarta.persistence-api.version>3.1.0</jakarta.persistence-api.version>
<jakarta.persistence-api.version>3.2.0</jakarta.persistence-api.version>
<jakarta.resource-api.version>2.1.0</jakarta.resource-api.version>
<jakarta.servlet-api.version>6.0.0</jakarta.servlet-api.version>
<jakarta.transaction-api.version>2.0.1</jakarta.transaction-api.version>
Expand Down Expand Up @@ -5211,10 +5211,11 @@
<version>${hibernate-orm.version}</version>
<exclusions>
<!-- We don't want Jandex at runtime -->
<exclusion>
<!-- ... but right now we need it: https://github.com/hibernate/hibernate-models/issues/85 -->
<!-- <exclusion>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
</exclusion>
</exclusion> -->
</exclusions>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static DotName createConstant(String fqcn) {
public static final DotName XML_FORMAT = createConstant("io.quarkus.hibernate.orm.XmlFormat");

public static final List<DotName> GENERATORS = List.of(
createConstant("org.hibernate.generator.Assigned"),
createConstant("org.hibernate.generator.internal.CurrentTimestampGeneration"),
createConstant("org.hibernate.generator.internal.GeneratedAlwaysGeneration"),
createConstant("org.hibernate.generator.internal.GeneratedGeneration"),
Expand All @@ -79,8 +80,6 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.id.enhanced.SequenceStyleGenerator"),
createConstant("org.hibernate.id.enhanced.TableGenerator"),
createConstant("org.hibernate.id.uuid.UuidGenerator"),
createConstant("org.hibernate.tuple.CreationTimestampGeneration"),
createConstant("org.hibernate.tuple.UpdateTimestampGeneration"),
createConstant("org.hibernate.tuple.VmValueGeneration"));

public static final List<DotName> PACKAGE_ANNOTATIONS = List.of(
Expand Down Expand Up @@ -110,7 +109,11 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.annotations.NamedNativeQuery"),
createConstant("org.hibernate.annotations.NamedQueries"),
createConstant("org.hibernate.annotations.NamedQuery"),
createConstant("jakarta.persistence.SequenceGenerator"),
createConstant("jakarta.persistence.SequenceGenerators"),
createConstant("org.hibernate.annotations.SoftDelete"),
createConstant("jakarta.persistence.TableGenerator"),
createConstant("jakarta.persistence.TableGenerators"),
createConstant("org.hibernate.annotations.TypeRegistration"),
createConstant("org.hibernate.annotations.TypeRegistrations"));

Expand All @@ -122,6 +125,7 @@ private static DotName createConstant(String fqcn) {
createConstant("jakarta.persistence.AttributeOverrides"),
createConstant("jakarta.persistence.Basic"),
createConstant("jakarta.persistence.Cacheable"),
createConstant("jakarta.persistence.CheckConstraint"),
createConstant("jakarta.persistence.CollectionTable"),
createConstant("jakarta.persistence.Column"),
createConstant("jakarta.persistence.ColumnResult"),
Expand All @@ -135,6 +139,7 @@ private static DotName createConstant(String fqcn) {
createConstant("jakarta.persistence.Embeddable"),
createConstant("jakarta.persistence.Embedded"),
createConstant("jakarta.persistence.EmbeddedId"),
createConstant("jakarta.persistence.EnumeratedValue"),
createConstant("jakarta.persistence.Entity"),
createConstant("jakarta.persistence.EntityListeners"),
createConstant("jakarta.persistence.EntityResult"),
Expand Down Expand Up @@ -247,6 +252,7 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.annotations.ConcreteProxy"),
createConstant("org.hibernate.annotations.ConverterRegistration"),
createConstant("org.hibernate.annotations.ConverterRegistrations"),
createConstant("org.hibernate.boot.models.Copied"),
createConstant("org.hibernate.annotations.CreationTimestamp"),
createConstant("org.hibernate.annotations.CurrentTimestamp"),
createConstant("org.hibernate.annotations.DialectOverride$Check"),
Expand Down Expand Up @@ -360,8 +366,8 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.annotations.Parameter"),
createConstant("org.hibernate.annotations.Parent"),
createConstant("org.hibernate.annotations.PartitionKey"),
createConstant("org.hibernate.annotations.Persister"),
createConstant("org.hibernate.annotations.Polymorphism"),
createConstant("org.hibernate.annotations.PropertyRef"),
createConstant("org.hibernate.annotations.Proxy"),
createConstant("org.hibernate.annotations.QueryCacheLayout"),
createConstant("org.hibernate.annotations.RowId"),
Expand Down Expand Up @@ -454,5 +460,4 @@ private static DotName createConstant(String fqcn) {
createConstant("java.util.TimeZone"),
createConstant("java.util.UUID"),
createConstant("java.lang.Void"));

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.jpa.boot.spi.JpaSettings;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.jpa.boot.spi.PersistenceXmlParser;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget.Kind;
import org.jboss.jandex.AnnotationValue;
Expand Down Expand Up @@ -130,6 +130,7 @@
import io.quarkus.hibernate.orm.runtime.proxies.PreGeneratedProxies;
import io.quarkus.hibernate.orm.runtime.recording.RecordedConfig;
import io.quarkus.hibernate.orm.runtime.schema.SchemaManagementIntegrator;
import io.quarkus.hibernate.orm.runtime.service.FlatClassLoaderService;
import io.quarkus.hibernate.orm.runtime.tenant.DataSourceTenantConnectionResolver;
import io.quarkus.hibernate.orm.runtime.tenant.TenantConnectionResolver;
import io.quarkus.panache.common.deployment.HibernateEnhancersRegisteredBuildItem;
Expand Down Expand Up @@ -256,8 +257,12 @@ List<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles(HibernateOrmCo
public void parsePersistenceXmlDescriptors(HibernateOrmConfig config,
BuildProducer<PersistenceXmlDescriptorBuildItem> persistenceXmlDescriptorBuildItemBuildProducer) {
if (!shouldIgnorePersistenceXmlResources(config)) {
var explicitDescriptors = QuarkusPersistenceXmlParser.locatePersistenceUnits();
for (var desc : explicitDescriptors) {
var parser = PersistenceXmlParser.create(Map.of(), null, FlatClassLoaderService.INSTANCE);
var urls = parser.getClassLoaderService().locateResources("META-INF/persistence.xml");
if (urls.isEmpty()) {
return;
}
for (var desc : parser.parse(urls).values()) {
persistenceXmlDescriptorBuildItemBuildProducer.produce(new PersistenceXmlDescriptorBuildItem(desc));
}
}
Expand Down Expand Up @@ -973,7 +978,6 @@ private static void producePersistenceUnitDescriptorFromConfig(
if (batchSize > 0) {
descriptor.getProperties().setProperty(AvailableSettings.DEFAULT_BATCH_FETCH_SIZE,
Integer.toString(batchSize));
descriptor.getProperties().setProperty(AvailableSettings.BATCH_FETCH_STYLE, BatchFetchStyle.PADDED.toString());
}

if (persistenceUnitConfig.fetch().maxDepth().isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmJoinedSubclassEntityType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmRootEntityType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmUnionSubclassEntityType;
import org.hibernate.boot.jaxb.mapping.EntityOrMappedSuperclass;
import org.hibernate.boot.jaxb.mapping.JaxbConverter;
import org.hibernate.boot.jaxb.mapping.JaxbEmbeddable;
import org.hibernate.boot.jaxb.mapping.JaxbEntity;
import org.hibernate.boot.jaxb.mapping.JaxbEntityListener;
import org.hibernate.boot.jaxb.mapping.JaxbEntityListeners;
import org.hibernate.boot.jaxb.mapping.JaxbEntityMappings;
import org.hibernate.boot.jaxb.mapping.JaxbMappedSuperclass;
import org.hibernate.boot.jaxb.mapping.JaxbPersistenceUnitDefaults;
import org.hibernate.boot.jaxb.mapping.JaxbPersistenceUnitMetadata;
import org.hibernate.boot.jaxb.mapping.ManagedType;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntity;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerContainerImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityOrMappedSuperclass;
import org.hibernate.boot.jaxb.mapping.spi.JaxbManagedType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
Expand Down Expand Up @@ -185,32 +179,33 @@ private void enlistExplicitMappings(Collector collector,
}
}

private void enlistOrmXmlMapping(Collector collector, JaxbEntityMappings mapping) {
private void enlistOrmXmlMapping(Collector collector, JaxbEntityMappingsImpl mapping) {
String packageName = mapping.getPackage();
String packagePrefix = packageName == null ? "" : packageName + ".";

JaxbPersistenceUnitMetadata metadata = mapping.getPersistenceUnitMetadata();
JaxbPersistenceUnitDefaults defaults = metadata == null ? null : metadata.getPersistenceUnitDefaults();
var metadata = mapping.getPersistenceUnitMetadata();
var defaults = metadata == null ? null : metadata.getPersistenceUnitDefaults();
if (defaults != null) {
enlistOrmXmlMappingListeners(collector, packagePrefix, defaults.getEntityListeners());
enlistOrmXmlMappingListeners(collector, packagePrefix, defaults.getEntityListenerContainer());
}

for (JaxbEntity entity : mapping.getEntities()) {
for (var entity : mapping.getEntities()) {
enlistOrmXmlMappingManagedClass(collector, packagePrefix, entity, "entity");
}
for (JaxbMappedSuperclass mappedSuperclass : mapping.getMappedSuperclasses()) {
for (var mappedSuperclass : mapping.getMappedSuperclasses()) {
enlistOrmXmlMappingManagedClass(collector, packagePrefix, mappedSuperclass, "mapped-superclass");
}
for (JaxbEmbeddable embeddable : mapping.getEmbeddables()) {
for (var embeddable : mapping.getEmbeddables()) {
String name = safeGetClassName(packagePrefix, embeddable, "embeddable");
enlistExplicitClass(collector, name);
}
for (JaxbConverter converter : mapping.getConverters()) {
for (var converter : mapping.getConverters()) {
collector.potentialCdiBeanTypes.add(DotName.createSimple(qualifyIfNecessary(packagePrefix, converter.getClazz())));
}
}

private void enlistOrmXmlMappingManagedClass(Collector collector, String packagePrefix, EntityOrMappedSuperclass managed,
private void enlistOrmXmlMappingManagedClass(Collector collector, String packagePrefix,
JaxbEntityOrMappedSuperclass managed,
String nodeName) {
String name = safeGetClassName(packagePrefix, managed, nodeName);
enlistExplicitClass(collector, name);
Expand All @@ -220,19 +215,20 @@ private void enlistOrmXmlMappingManagedClass(Collector collector, String package
collector.entityTypes.add(name);
}

enlistOrmXmlMappingListeners(collector, packagePrefix, managed.getEntityListeners());
enlistOrmXmlMappingListeners(collector, packagePrefix, managed.getEntityListenerContainer());
}

private void enlistOrmXmlMappingListeners(Collector collector, String packagePrefix, JaxbEntityListeners entityListeners) {
private void enlistOrmXmlMappingListeners(Collector collector, String packagePrefix,
JaxbEntityListenerContainerImpl entityListeners) {
if (entityListeners == null) {
return;
}
for (JaxbEntityListener listener : entityListeners.getEntityListener()) {
for (var listener : entityListeners.getEntityListeners()) {
collector.potentialCdiBeanTypes.add(DotName.createSimple(qualifyIfNecessary(packagePrefix, listener.getClazz())));
}
}

private static String safeGetClassName(String packagePrefix, ManagedType managedType, String nodeName) {
private static String safeGetClassName(String packagePrefix, JaxbManagedType managedType, String nodeName) {
String name = managedType.getClazz();
if (name == null) {
throw new IllegalArgumentException("Missing attribute '" + nodeName + ".class'");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.hibernate.boot.archive.internal.ArchiveHelper;
import org.hibernate.boot.jaxb.spi.Binding;
import org.hibernate.boot.jaxb.spi.JaxbBindableMappingDescriptor;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
Expand Down Expand Up @@ -62,7 +63,7 @@ public Optional<RecordableXmlMapping> parse(String persistenceUnitName, URL pers
}

try (InputStream stream = url.openStream()) {
Binding<?> binding = (Binding<?>) binderAccess.bind(stream);
Binding<? extends JaxbBindableMappingDescriptor> binding = binderAccess.bind(stream);
return Optional.of(RecordableXmlMapping.create(binding));
} catch (RuntimeException | IOException e) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ public void setId(EmbeddableIdWithAnnotation id) {
}
}

@MappedSuperclass
public interface Identifiable {
Object getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.sql.DataSource;

import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceConfiguration;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.spi.PersistenceProvider;
import jakarta.persistence.spi.PersistenceUnitInfo;
Expand Down Expand Up @@ -81,6 +82,14 @@ public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitI
return getEntityManagerFactoryBuilder(info, properties).build();
}

@Override
public EntityManagerFactory createEntityManagerFactory(PersistenceConfiguration configuration) {
throw new PersistenceException(
"This PersistenceProvider does not support createEntityManagerFactory(PersistenceConfiguration). "
+ " Quarkus is responsible for creating the entity manager factory, so inject your entity manager"
+ " factory through CDI instead: `@Inject EntityManagerFactory emf`.");
}

@SuppressWarnings("rawtypes")
@Override
public void generateSchema(PersistenceUnitInfo info, Map map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.function.Supplier;

import jakarta.persistence.EntityGraph;
import jakarta.persistence.TypedQueryReference;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
Expand Down Expand Up @@ -276,6 +277,11 @@ public Query createQuery(CriteriaDelete deleteQuery) {
return delegate.get().createQuery(deleteQuery);
}

@Override
public <R> Query<R> createQuery(TypedQueryReference<R> typedQueryReference) {
return delegate.get().createQuery(typedQueryReference);
}

@Override
@Deprecated(since = "6.0")
public NativeQuery createNativeQuery(String sqlString) {
Expand Down
Loading

0 comments on commit af4a80c

Please sign in to comment.