Skip to content

Commit

Permalink
Fix compilation errors with latest snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Jan 17, 2025
1 parent b2da8fe commit 2ff433c
Show file tree
Hide file tree
Showing 40 changed files with 305 additions and 720 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ org.gradle.java.installations.auto-download=false
#db = MSSQL

# Enable the SonatypeOS maven repository (mainly for Vert.x snapshots) when present (value ignored)
enableSonatypeOpenSourceSnapshotsRep = true
#enableSonatypeOpenSourceSnapshotsRep = true

# Enable the maven local repository (for local development when needed) when present (value ignored)
#enableMavenLocalRepo = true
enableMavenLocalRepo = true

# The default Hibernate ORM version (override using `-PhibernateOrmVersion=the.version.you.want`)
hibernateOrmVersion = 7.0.0-SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public static CompletionStage<Object> resolve(EntityType entityType, Object idOr
* @see OneToOneType#isNull(Object, SharedSessionContractImplementor)
*/
static boolean isNull(EntityType entityType, Object owner, SharedSessionContractImplementor session) {
if ( entityType instanceof OneToOneType ) {
OneToOneType type = (OneToOneType) entityType;
if ( entityType instanceof OneToOneType type ) {
String propertyName = type.getPropertyName();
if ( propertyName != null ) {
final EntityPersister ownerPersister = session.getFactory()
Expand Down Expand Up @@ -125,7 +124,7 @@ static CompletionStage<Object> loadByUniqueKey(
entityName,
uniqueKeyPropertyName,
key,
entityType.getIdentifierOrUniqueKeyType( factory ),
entityType.getIdentifierOrUniqueKeyType( factory.getRuntimeMetamodels() ),
factory
);

Expand Down Expand Up @@ -338,7 +337,7 @@ private static CompletionStage<Object> resolveIdOrUniqueKey(
// ORM this is unnecessary due to transparent lazy fetching.)
return ( (ReactiveSessionImpl) session ).reactiveFetch( id, true )
.thenCompose( fetched -> {
Object idOrUniqueKey = entityType.getIdentifierOrUniqueKeyType( session.getFactory() )
Object idOrUniqueKey = entityType.getIdentifierOrUniqueKeyType( session.getFactory().getRuntimeMetamodels() )
.replace( fetched, null, session, owner, copyCache );
if ( idOrUniqueKey instanceof CompletionStage ) {
return ( (CompletionStage<?>) idOrUniqueKey )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void execute() throws HibernateException {
}

private void preRecreate() {
getFastSessionServices()
getEventListenerGroups()
.eventListenerGroup_PRE_COLLECTION_RECREATE
.fireLazyEventOnEachListener( this::newPreCollectionRecreateEvent, PreCollectionRecreateEventListener::onPreRecreateCollection );
}
Expand All @@ -66,7 +66,7 @@ private PreCollectionRecreateEvent newPreCollectionRecreateEvent() {
}

private void postRecreate() {
getFastSessionServices()
getEventListenerGroups()
.eventListenerGroup_POST_COLLECTION_RECREATE
.fireLazyEventOnEachListener( this::newPostCollectionRecreateEvent, PostCollectionRecreateEventListener::onPostRecreateCollection );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public void execute() throws HibernateException {
}

private void preRemove() {
getFastSessionServices().eventListenerGroup_PRE_COLLECTION_REMOVE
getEventListenerGroups()
.eventListenerGroup_PRE_COLLECTION_REMOVE
.fireLazyEventOnEachListener( this::newPreCollectionRemoveEvent,
PreCollectionRemoveEventListener::onPreRemoveCollection );
}
Expand All @@ -115,7 +116,8 @@ private PreCollectionRemoveEvent newPreCollectionRemoveEvent() {
}

private void postRemove() {
getFastSessionServices().eventListenerGroup_POST_COLLECTION_REMOVE
getEventListenerGroups()
.eventListenerGroup_POST_COLLECTION_REMOVE
.fireLazyEventOnEachListener( this::newPostCollectionRemoveEvent,
PostCollectionRemoveEventListener::onPostRemoveCollection );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public void execute() throws HibernateException {
}

private void preUpdate() {
getFastSessionServices().eventListenerGroup_PRE_COLLECTION_UPDATE
getEventListenerGroups()
.eventListenerGroup_PRE_COLLECTION_UPDATE
.fireLazyEventOnEachListener( this::newPreCollectionUpdateEvent,
PreCollectionUpdateEventListener::onPreUpdateCollection );
}
Expand All @@ -132,7 +133,8 @@ private PreCollectionUpdateEvent newPreCollectionUpdateEvent() {
}

private void postUpdate() {
getFastSessionServices().eventListenerGroup_POST_COLLECTION_UPDATE
getEventListenerGroups()
.eventListenerGroup_POST_COLLECTION_UPDATE
.fireLazyEventOnEachListener( this::newPostCollectionUpdateEvent,
PostCollectionUpdateEventListener::onPostUpdateCollection );
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ protected void logFlushResults(FlushEvent event) {
session.getActionQueue().numberOfCollectionRemovals(),
persistenceContext.getCollectionEntriesSize()
);
new EntityPrinter( session.getFactory() ).toString(
persistenceContext.getEntityHoldersByKey().entrySet()
);
new EntityPrinter( session.getFactory() )
.logEntities( persistenceContext.getEntityHoldersByKey().entrySet() );
}

/**
Expand Down Expand Up @@ -227,7 +226,7 @@ private int flushEntities(final FlushEvent event, final PersistenceContext persi
final EventSource source = event.getSession();
final Iterable<FlushEntityEventListener> flushListeners =
source.getFactory()
.getFastSessionServices()
.getEventListenerGroups()
.eventListenerGroup_FLUSH_ENTITY
.listeners();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.hibernate.TransientObjectException;
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.internal.CascadePoint;
import org.hibernate.engine.internal.Nullability;
import org.hibernate.engine.spi.EntityEntry;
Expand All @@ -22,13 +21,13 @@
import org.hibernate.engine.spi.Status;
import org.hibernate.event.internal.OnUpdateVisitor;
import org.hibernate.event.internal.PostDeleteEventListenerStandardImpl;
import org.hibernate.event.service.spi.EventListenerGroups;
import org.hibernate.event.service.spi.JpaBootstrapSensitive;
import org.hibernate.event.spi.DeleteContext;
import org.hibernate.event.spi.DeleteEvent;
import org.hibernate.event.spi.DeleteEventListener;
import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.EmptyInterceptor;
import org.hibernate.internal.FastSessionServices;
import org.hibernate.jpa.event.spi.CallbackRegistry;
import org.hibernate.jpa.event.spi.CallbackRegistryConsumer;
import org.hibernate.jpa.event.spi.CallbackType;
Expand Down Expand Up @@ -205,17 +204,6 @@ private CompletionStage<Void> fetchAndDelete(DeleteEvent event, DeleteContext tr

}

protected boolean invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) {
if ( persister.implementsLifecycle() ) {
LOG.debug( "Calling onDelete()" );
if ( ( (Lifecycle) entity ).onDelete( session ) ) {
LOG.debug( "Deletion vetoed by onDelete()" );
return true;
}
}
return false;
}

private CompletionStage<Void> deleteTransientInstance(DeleteEvent event, DeleteContext transientEntities, Object entity) {
LOG.trace( "Entity was not persistent in delete processing" );

Expand Down Expand Up @@ -291,31 +279,27 @@ private CompletionStage<Void> delete(
Object version,
EntityEntry entry) {
callbackRegistry.preRemove( entity );
if ( !invokeDeleteLifecycle( source, entity, persister ) ) {
return deleteEntity(
source,
entity,
entry,
event.isCascadeDeleteEnabled(),
event.isOrphanRemovalBeforeUpdates(),
persister,
transientEntities
)
.thenAccept( v -> {
if ( source.getFactory().getSessionFactoryOptions().isIdentifierRollbackEnabled() ) {
persister.resetIdentifier( entity, id, version, source );
}
} );
}
return voidFuture();
return deleteEntity(
source,
entity,
entry,
event.isCascadeDeleteEnabled(),
event.isOrphanRemovalBeforeUpdates(),
persister,
transientEntities
)
.thenAccept( v -> {
if ( source.getFactory().getSessionFactoryOptions().isIdentifierRollbackEnabled() ) {
persister.resetIdentifier( entity, id, version, source );
}
} );
}

/**
* Can we delete the row represented by the proxy without loading the entity?
*/
private boolean canBeDeletedWithoutLoading(EventSource source, EntityPersister persister) {
return source.getInterceptor() == EmptyInterceptor.INSTANCE
&& !persister.implementsLifecycle()
&& !persister.hasSubclasses() //TODO: should be unnecessary, using EntityPersister.getSubclassPropertyTypeClosure(), etc
&& !persister.hasCascadeDelete()
&& !persister.hasNaturalIdentifier()
Expand All @@ -325,7 +309,7 @@ private boolean canBeDeletedWithoutLoading(EventSource source, EntityPersister p
}

private static boolean hasCustomEventListeners(EventSource source) {
final FastSessionServices fss = source.getFactory().getFastSessionServices();
final EventListenerGroups fss = source.getFactory().getEventListenerGroups();
// Bean Validation adds a PRE_DELETE listener
// and Envers adds a POST_DELETE listener
return fss.eventListenerGroup_PRE_DELETE.count() > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.LoadEvent;
import org.hibernate.event.spi.LoadEventListener;
import org.hibernate.loader.ast.internal.CacheEntityLoaderHelper;
import org.hibernate.loader.ast.internal.CacheEntityLoaderHelper.PersistenceContextEntry;
import org.hibernate.loader.internal.CacheLoadHelper;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMappingsList;
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
Expand All @@ -40,7 +39,6 @@
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.reactive.event.ReactiveLoadEventListener;
import org.hibernate.reactive.loader.entity.ReactiveCacheEntityLoaderHelper;
import org.hibernate.reactive.logging.impl.Log;
import org.hibernate.reactive.logging.impl.LoggerFactory;
import org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister;
Expand All @@ -49,7 +47,10 @@

import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
import static org.hibernate.loader.internal.CacheLoadHelper.loadFromSecondLevelCache;
import static org.hibernate.loader.internal.CacheLoadHelper.loadFromSessionCache;
import static org.hibernate.pretty.MessageHelper.infoString;
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
import static org.hibernate.reactive.session.impl.SessionUtil.checkEntityFound;
import static org.hibernate.reactive.session.impl.SessionUtil.throwEntityNotFound;
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
Expand Down Expand Up @@ -399,7 +400,7 @@ private static CompletionStage<Object> loadWithProxyFactory(LoadEvent event, Ent

if ( proxy != null ) {
LOG.trace( "Entity proxy found in session cache" );
if ( LOG.isDebugEnabled() && HibernateProxy.extractLazyInitializer( proxy ).isUnwrap() ) {
if ( LOG.isDebugEnabled() && extractLazyInitializer( proxy ).isUnwrap() ) {
LOG.debug( "Ignoring NO_PROXY to honor laziness" );
}

Expand Down Expand Up @@ -429,7 +430,7 @@ private static PersistentAttributeInterceptable createBatchLoadableEnhancedProxy
}

private static Object proxyOrCached(LoadEvent event, EntityPersister persister, EntityKey keyToLoad) {
final Object cachedEntity = CacheEntityLoaderHelper.INSTANCE.loadFromSecondLevelCache(
final Object cachedEntity = loadFromSecondLevelCache(
event.getSession(),
null,
LockMode.NONE,
Expand All @@ -450,7 +451,7 @@ private static Object proxyOrCached(LoadEvent event, EntityPersister persister,
return options.isCheckDeleted() && wasDeleted( persistenceContext, existing ) ? null : existing;
}
if ( persister.hasSubclasses() ) {
final Object cachedEntity = CacheEntityLoaderHelper.INSTANCE.loadFromSecondLevelCache(
final Object cachedEntity = loadFromSecondLevelCache(
event.getSession(),
null,
LockMode.NONE,
Expand Down Expand Up @@ -652,9 +653,9 @@ private CompletionStage<Object> doLoad(
return nullFuture();
}
else {
final PersistenceContextEntry persistenceContextEntry =
ReactiveCacheEntityLoaderHelper.INSTANCE.loadFromSessionCache( event, keyToLoad, options );
final Object entity = persistenceContextEntry.getEntity();
final CacheLoadHelper.PersistenceContextEntry persistenceContextEntry =
loadFromSessionCache( keyToLoad, event.getLockOptions(), options, event.getSession() );
final Object entity = persistenceContextEntry.entity();
if ( entity != null ) {
return persistenceContextEntry.isManaged() ? initializeIfNecessary( entity ) : nullFuture();
}
Expand All @@ -668,9 +669,7 @@ private static CompletionStage<Object> initializeIfNecessary(Object entity) {
if ( isPersistentAttributeInterceptable( entity ) ) {
final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable( entity );
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor) {
final EnhancementAsProxyLazinessInterceptor lazinessInterceptor =
(EnhancementAsProxyLazinessInterceptor) interceptor;
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) {
final SharedSessionContractImplementor session = lazinessInterceptor.getLinkedSession();
if ( session == null ) {
throw LOG.sessionClosedLazyInitializationException();
Expand All @@ -691,7 +690,8 @@ private CompletionStage<Object> loadFromCacheOrDatasource(
EntityPersister persister,
EntityKey keyToLoad) {
final EventSource session = event.getSession();
final Object entity = CacheEntityLoaderHelper.INSTANCE.loadFromSecondLevelCache(event, persister, keyToLoad);
final Object entity = session
.loadFromSecondLevelCache( persister, keyToLoad, event.getInstanceToLoad(), event.getLockMode() );
if ( entity != null ) {
if ( LOG.isTraceEnabled() ) {
LOG.tracev(
Expand Down Expand Up @@ -740,6 +740,10 @@ private void cacheNaturalId(LoadEvent event, EntityPersister persister, EventSou
* @return The object loaded from the datasource, or null if not found.
*/
protected CompletionStage<Object> loadFromDatasource(LoadEvent event, EntityPersister persister) {
if ( LOG.isTraceEnabled() ) {
LOG.trace( "Entity not resolved in any cache, loading from datastore: "
+ infoString( persister, event.getEntityId(), event.getFactory() ) );
}
return ( (ReactiveEntityPersister) persister )
.reactiveLoad(
event.getEntityId(),
Expand All @@ -754,16 +758,14 @@ protected CompletionStage<Object> loadFromDatasource(LoadEvent event, EntityPers
// persister/loader/initializer sensitive to this fact - possibly
// passing LoadType along

final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( entity );
if ( lazyInitializer != null ) {
entity = lazyInitializer.getImplementation();
}
final LazyInitializer lazyInitializer = extractLazyInitializer( entity );
final Object impl = lazyInitializer != null ? lazyInitializer.getImplementation() : entity;

final StatisticsImplementor statistics = event.getSession().getFactory().getStatistics();
if ( event.isAssociationFetch() && statistics.isStatisticsEnabled() ) {
statistics.fetchEntity( event.getEntityClassName() );
}
return entity;
return impl;
} );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ protected Map<Object, Object> getMergeMap(MergeContext context) {
@Override
public CompletionStage<Void> reactiveOnMerge(MergeEvent event) throws HibernateException {
final EventSource session = event.getSession();
final EntityCopyObserver entityCopyObserver = createEntityCopyObserver( session );
final EntityCopyObserver entityCopyObserver = session.getFactory()
.getEntityCopyObserver()
.createEntityCopyObserver();
final MergeContext mergeContext = new MergeContext( session, entityCopyObserver );
return reactiveOnMerge( event, mergeContext )
.thenAccept( v -> entityCopyObserver.topLevelMergeComplete( session ) )
Expand All @@ -104,10 +106,6 @@ public CompletionStage<Void> reactiveOnMerge(MergeEvent event) throws HibernateE
} );
}

private EntityCopyObserver createEntityCopyObserver(final EventSource session) {
return session.getFactory().getFastSessionServices().entityCopyObserverFactory.createEntityCopyObserver();
}

/**
* Handle the given merge event.
*
Expand Down
Loading

0 comments on commit 2ff433c

Please sign in to comment.