Skip to content

Commit

Permalink
Upgrade to Hibernate ORM 7.0.0.Beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Sep 13, 2024
1 parent e794f3f commit 464af78
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ private static DotName createConstant(String fqcn) {
public static final DotName EMBEDDED = createConstant("jakarta.persistence.Embedded");
public static final DotName EMBEDDED_ID = createConstant("jakarta.persistence.EmbeddedId");
public static final DotName ELEMENT_COLLECTION = createConstant("jakarta.persistence.ElementCollection");
public static final DotName PROXY = createConstant("org.hibernate.annotations.Proxy");
public static final DotName HIBERNATE_PROXY = createConstant("org.hibernate.proxy.HibernateProxy");
public static final DotName TYPE = createConstant("org.hibernate.annotations.Type");
public static final DotName INJECT_SERVICE = createConstant("org.hibernate.service.spi.InjectService");
Expand Down Expand Up @@ -79,8 +78,7 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.id.UUIDHexGenerator"),
createConstant("org.hibernate.id.enhanced.SequenceStyleGenerator"),
createConstant("org.hibernate.id.enhanced.TableGenerator"),
createConstant("org.hibernate.id.uuid.UuidGenerator"),
createConstant("org.hibernate.tuple.VmValueGeneration"));
createConstant("org.hibernate.id.uuid.UuidGenerator"));

public static final List<DotName> PACKAGE_ANNOTATIONS = List.of(
createConstant("org.hibernate.annotations.CollectionTypeRegistration"),
Expand Down Expand Up @@ -289,8 +287,6 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.annotations.DialectOverride$SQLUpdate"),
createConstant("org.hibernate.annotations.DialectOverride$SQLUpdates"),
createConstant("org.hibernate.annotations.DialectOverride$Version"),
createConstant("org.hibernate.annotations.DialectOverride$Where"),
createConstant("org.hibernate.annotations.DialectOverride$Wheres"),
createConstant("org.hibernate.annotations.DiscriminatorFormula"),
createConstant("org.hibernate.annotations.DiscriminatorOptions"),
createConstant("org.hibernate.annotations.DynamicInsert"),
Expand All @@ -310,20 +306,16 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.annotations.FilterJoinTable"),
createConstant("org.hibernate.annotations.FilterJoinTables"),
createConstant("org.hibernate.annotations.Filters"),
createConstant("org.hibernate.annotations.ForeignKey"),
createConstant("org.hibernate.annotations.Formula"),
createConstant("org.hibernate.annotations.FractionalSeconds"),
createConstant("org.hibernate.annotations.Generated"),
createConstant("org.hibernate.annotations.GeneratedColumn"),
createConstant("org.hibernate.annotations.GeneratorType"),
createConstant("org.hibernate.annotations.GenericGenerator"),
createConstant("org.hibernate.annotations.GenericGenerators"),
createConstant("org.hibernate.annotations.HQLSelect"),
createConstant("org.hibernate.annotations.IdGeneratorType"),
createConstant("org.hibernate.annotations.Immutable"),
createConstant("org.hibernate.annotations.Imported"),
createConstant("org.hibernate.annotations.Index"),
createConstant("org.hibernate.annotations.IndexColumn"),
createConstant("org.hibernate.annotations.Instantiator"),
createConstant("org.hibernate.annotations.JavaType"),
createConstant("org.hibernate.annotations.JavaTypeRegistration"),
Expand All @@ -335,14 +327,11 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.annotations.JoinColumnOrFormula"),
createConstant("org.hibernate.annotations.JoinColumnsOrFormulas"),
createConstant("org.hibernate.annotations.JoinFormula"),
createConstant("org.hibernate.annotations.LazyCollection"),
createConstant("org.hibernate.annotations.LazyGroup"),
createConstant("org.hibernate.annotations.LazyToOne"),
createConstant("org.hibernate.annotations.ListIndexBase"),
createConstant("org.hibernate.annotations.ListIndexJavaType"),
createConstant("org.hibernate.annotations.ListIndexJdbcType"),
createConstant("org.hibernate.annotations.ListIndexJdbcTypeCode"),
createConstant("org.hibernate.annotations.Loader"),
createConstant("org.hibernate.annotations.ManyToAny"),
createConstant("org.hibernate.annotations.MapKeyJavaType"),
createConstant("org.hibernate.annotations.MapKeyJdbcType"),
Expand All @@ -366,9 +355,7 @@ 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.Polymorphism"),
createConstant("org.hibernate.annotations.PropertyRef"),
createConstant("org.hibernate.annotations.Proxy"),
createConstant("org.hibernate.annotations.QueryCacheLayout"),
createConstant("org.hibernate.annotations.RowId"),
createConstant("org.hibernate.annotations.SQLDelete"),
Expand All @@ -384,7 +371,6 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.annotations.SQLUpdates"),
createConstant("org.hibernate.annotations.SecondaryRow"),
createConstant("org.hibernate.annotations.SecondaryRows"),
createConstant("org.hibernate.annotations.SelectBeforeUpdate"),
createConstant("org.hibernate.annotations.SoftDelete"),
createConstant("org.hibernate.annotations.SortComparator"),
createConstant("org.hibernate.annotations.SortNatural"),
Expand All @@ -393,8 +379,6 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.annotations.Struct"),
createConstant("org.hibernate.annotations.Subselect"),
createConstant("org.hibernate.annotations.Synchronize"),
createConstant("org.hibernate.annotations.Table"),
createConstant("org.hibernate.annotations.Tables"),
createConstant("org.hibernate.annotations.Target"),
createConstant("org.hibernate.annotations.TenantId"),
createConstant("org.hibernate.annotations.TimeZoneColumn"),
Expand All @@ -406,9 +390,7 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.annotations.UpdateTimestamp"),
createConstant("org.hibernate.annotations.UuidGenerator"),
createConstant("org.hibernate.annotations.ValueGenerationType"),
createConstant("org.hibernate.annotations.View"),
createConstant("org.hibernate.annotations.Where"),
createConstant("org.hibernate.annotations.WhereJoinTable"));
createConstant("org.hibernate.annotations.View"));

public static final List<DotName> ANNOTATED_WITH_INJECT_SERVICE = List.of(
createConstant("org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.hibernate.jpa.boot.spi.PersistenceXmlParser;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget.Kind;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.CompositeIndex;
import org.jboss.jandex.DotName;
Expand Down Expand Up @@ -1535,14 +1534,6 @@ private PreGeneratedProxies generatedProxies(Set<String> managedClassAndPackageN
}
//create a map of entity to proxy type
PreGeneratedProxies preGeneratedProxies = new PreGeneratedProxies();
Map<String, String> proxyAnnotations = new HashMap<>();
for (AnnotationInstance i : combinedIndex.getAnnotations(ClassNames.PROXY)) {
AnnotationValue proxyClass = i.value("proxyClass");
if (proxyClass == null) {
continue;
}
proxyAnnotations.put(i.target().asClass().name().toString(), proxyClass.asClass().name().toString());
}
TypePool transformedClassesTypePool = createTransformedClassesTypePool(transformedClassesBuildItem,
managedClassAndPackageNames);
try (ProxyBuildingHelper proxyHelper = new ProxyBuildingHelper(transformedClassesTypePool)) {
Expand All @@ -1554,28 +1545,11 @@ private PreGeneratedProxies generatedProxies(Set<String> managedClassAndPackageN
} else {
Set<String> proxyInterfaceNames = new TreeSet<>();
proxyInterfaceNames.add(ClassNames.HIBERNATE_PROXY.toString()); //always added
String proxy = proxyAnnotations.get(managedClassOrPackageName);
if (proxy == null) {
if (!proxyHelper.isProxiable(managedClassOrPackageName)) {
//if there is no @Proxy we need to make sure the actual class is proxiable
continue;
}
} else {
proxyInterfaceNames.add(proxy);
if (!proxyHelper.isProxiable(managedClassOrPackageName)) {
// we need to make sure the actual class is proxiable
continue;
}
final String mappedClass = managedClassOrPackageName;
for (ClassInfo subclass : combinedIndex
.getAllKnownSubclasses(DotName.createSimple(managedClassOrPackageName))) {
String subclassName = subclass.name().toString();
if (!managedClassAndPackageNames.contains(subclassName)) {
//not an entity
continue;
}
proxy = proxyAnnotations.get(subclassName);
if (proxy != null) {
proxyInterfaceNames.add(proxy);
}
}
DynamicType.Unloaded<?> unloaded = proxyHelper.buildUnloadedProxy(mappedClass, proxyInterfaceNames);
result = new CachedProxy(unloaded, proxyInterfaceNames);
proxyCache.cache.put(managedClassOrPackageName, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -14,6 +13,7 @@
import jakarta.persistence.Table;
import jakarta.transaction.UserTransaction;

import org.hibernate.CallbackException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
Expand Down Expand Up @@ -124,7 +124,8 @@ public ApplicationScopedInterceptor() {
}

@Override
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
loadedIds.add(id);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -15,6 +14,7 @@
import jakarta.persistence.Table;
import jakarta.transaction.UserTransaction;

import org.hibernate.CallbackException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
Expand Down Expand Up @@ -127,7 +127,8 @@ public DependentInterceptor() {
}

@Override
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
loadedIds.add(id);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -16,6 +15,7 @@
import jakarta.transaction.TransactionScoped;
import jakarta.transaction.UserTransaction;

import org.hibernate.CallbackException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
Expand Down Expand Up @@ -129,7 +129,8 @@ public TransactionScopedInterceptor() {
}

@Override
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
loadedIds.add(id);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import jakarta.inject.Inject;
import jakarta.transaction.UserTransaction;

import org.hibernate.CallbackException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Session;
import org.hibernate.type.Type;
Expand Down Expand Up @@ -116,7 +116,8 @@ public MyDefaultPUInterceptor() {
}

@Override
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
loadedIds.add(id);
return false;
}
Expand All @@ -134,7 +135,8 @@ public MyInventoryPUInterceptor() {
}

@Override
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
loadedIds.add(id);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_IMPORT_FILES;

import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;

public class HibernateOrmDevIntegrator implements Integrator {

@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactoryImplementor,
SessionFactoryServiceRegistry sessionFactoryServiceRegistry) {
public void integrate(Metadata metadata, BootstrapContext bootstrapContext,
SessionFactoryImplementor sessionFactoryImplementor) {
HibernateOrmDevController.get().pushPersistenceUnit(
(String) sessionFactoryImplementor.getProperties()
.get(org.hibernate.cfg.AvailableSettings.PERSISTENCE_UNIT_NAME),
metadata, sessionFactoryServiceRegistry,
metadata, sessionFactoryImplementor.getServiceRegistry(),
(String) sessionFactoryImplementor.getProperties().get(HBM2DDL_IMPORT_FILES));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ public StandardServiceRegistryBuilder applySettings(Map<String, Object> settings
}

@Override
public void clearSettings() {
public StandardServiceRegistryBuilder clearSettings() {
settings.clear();
return this;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import java.util.concurrent.ConcurrentHashMap;

import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.tool.schema.SourceType;
import org.hibernate.tool.schema.TargetType;
Expand Down Expand Up @@ -49,10 +51,10 @@ public class SchemaManagementIntegrator implements Integrator, DatabaseSchemaPro
.synchronizedMap(new IdentityHashMap<>());

@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
public void integrate(Metadata metadata, BootstrapContext bootstrapContext,
SessionFactoryImplementor sessionFactory) {
String name = defaultName(sessionFactory);
metadataMap.put(name, new Holder(metadata, sessionFactory, serviceRegistry));
metadataMap.put(name, new Holder(metadata, sessionFactory, sessionFactory.getServiceRegistry()));
nameCache.put(sessionFactory, name);
}

Expand Down Expand Up @@ -186,9 +188,9 @@ public void resetAllDatabases() {
static class Holder {
final Metadata metadata;
final SessionFactoryImplementor sessionFactory;
final SessionFactoryServiceRegistry serviceRegistry;
final ServiceRegistryImplementor serviceRegistry;

Holder(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
Holder(Metadata metadata, SessionFactoryImplementor sessionFactory, ServiceRegistryImplementor serviceRegistry) {
this.metadata = metadata;
this.sessionFactory = sessionFactory;
this.serviceRegistry = serviceRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public List<StandardServiceInitiator<?>> initialInitiatorList() {
serviceInitiators.add(BatchBuilderInitiator.INSTANCE);
serviceInitiators.add(JdbcServicesInitiator.INSTANCE);
serviceInitiators.add(RefCursorSupportInitiator.INSTANCE);
serviceInitiators.add(StandardIdentifierGeneratorFactoryInitiator.INSTANCE);

serviceInitiators.add(QuarkusJtaPlatformInitiator.INSTANCE);

Expand Down
Loading

0 comments on commit 464af78

Please sign in to comment.