diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/CollectionLogger.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/CollectionLogger.java new file mode 100644 index 000000000000..765c54baf96e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/CollectionLogger.java @@ -0,0 +1,67 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.collection.internal; + +import org.hibernate.Internal; +import org.hibernate.internal.log.SubSystemLogging; + +import org.jboss.logging.BasicLogger; +import org.jboss.logging.Logger; +import org.jboss.logging.annotations.LogMessage; +import org.jboss.logging.annotations.Message; +import org.jboss.logging.annotations.MessageLogger; +import org.jboss.logging.annotations.ValidIdRange; + +import java.lang.invoke.MethodHandles; + +import static org.jboss.logging.Logger.Level.DEBUG; +import static org.jboss.logging.Logger.Level.INFO; +import static org.jboss.logging.Logger.Level.WARN; + +/** + * Subsystem logging related to PersistentCollection runtime events + */ +@SubSystemLogging( + name = CollectionLogger.NAME, + description = "Logging related to persistent collection lifecycle and operations" +) +@MessageLogger(projectCode = "HHH") +@ValidIdRange(min = 90030001, max = 90031000) +@Internal +public interface CollectionLogger extends BasicLogger { + String NAME = SubSystemLogging.BASE + ".collection"; + + CollectionLogger COLLECTION_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), CollectionLogger.class, NAME ); + + @LogMessage(level = WARN) + @Message(id = 90030001, value = "Unable to close temporary session used to load lazy collection associated to no session") + void unableToCloseTemporarySession(); + + @LogMessage(level = WARN) + @Message(id = 90030002, value = "Detaching an uninitialized collection with enabled filters from a session: %s") + void enabledFiltersWhenDetachFromSession(String collectionInfoString); + + @LogMessage(level = WARN) + @Message(id = 90030004, value = "Attaching an uninitialized collection with queued operations to a session: %s") + void queuedOperationWhenAttachToSession(String collectionInfoString); + + @LogMessage(level = INFO) + @Message(id = 90030005, value = "Detaching an uninitialized collection with queued operations from a session: %s") + void queuedOperationWhenDetachFromSession(String collectionInfoString); + + @LogMessage(level = DEBUG) + @Message(id = 90030006, value = "Detaching an uninitialized collection with queued operations from a session due to rollback: %s") + void queuedOperationWhenDetachFromSessionOnRollback(String collectionInfoString); + + @LogMessage(level = WARN) + @Message(id = 90030007, value = "Cannot unset session in a collection because an unexpected session is defined." + + " A persistent collection may only be associated with one session at a time. %s") + void logCannotUnsetUnexpectedSessionInCollection(String msg); + + @LogMessage(level = WARN) + @Message(id = 90030008, value = "An unexpected session is defined for a collection, but the collection is not connected to that session." + + " A persistent collection may only be associated with one session at a time. Overwriting session. %s") + void logUnexpectedSessionInCollectionNotConnected(String msg); +} diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java index 21ad34e33b29..a678d294aa3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java @@ -27,8 +27,6 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.Status; import org.hibernate.engine.spi.TypedValue; -import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.SessionFactoryRegistry; import org.hibernate.internal.util.MarkerObject; import org.hibernate.internal.util.collections.IdentitySet; @@ -40,6 +38,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import static java.util.Collections.emptyList; +import static org.hibernate.collection.internal.CollectionLogger.COLLECTION_LOGGER; import static org.hibernate.engine.internal.ForeignKeys.getEntityIdentifier; import static org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved; import static org.hibernate.engine.internal.ForeignKeys.isNotTransient; @@ -57,8 +56,6 @@ */ public abstract class AbstractPersistentCollection implements Serializable, PersistentCollection { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractPersistentCollection.class ); - private transient SharedSessionContractImplementor session; private boolean isTempSession = false; @@ -298,7 +295,7 @@ else if ( !session.isConnected() ) { tempSession.close(); } catch (Exception e) { - LOG.unableToCloseTemporarySession(); + COLLECTION_LOGGER.unableToCloseTemporarySession(); } } else { @@ -706,7 +703,7 @@ public final boolean unsetSession(SharedSessionContractImplementor currentSessio if ( allowLoadOutsideTransaction && !initialized && session.getLoadQueryInfluencers().hasEnabledFilters() ) { - LOG.enabledFiltersWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) ); + COLLECTION_LOGGER.enabledFiltersWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) ); } session = null; } @@ -714,7 +711,7 @@ public final boolean unsetSession(SharedSessionContractImplementor currentSessio } else { if ( session != null ) { - LOG.logCannotUnsetUnexpectedSessionInCollection( unexpectedSessionStateMessage( currentSession ) ); + COLLECTION_LOGGER.logCannotUnsetUnexpectedSessionInCollection( unexpectedSessionStateMessage( currentSession ) ); } return false; } @@ -724,20 +721,20 @@ private void logDiscardedQueuedOperations() { try { if ( wasTransactionRolledBack() ) { // It was due to a rollback. - if ( LOG.isDebugEnabled()) { - LOG.queuedOperationWhenDetachFromSessionOnRollback( collectionInfoString( getRole(), getKey() ) ); + if ( COLLECTION_LOGGER.isDebugEnabled()) { + COLLECTION_LOGGER.queuedOperationWhenDetachFromSessionOnRollback( collectionInfoString( getRole(), getKey() ) ); } } else { // We don't know why the collection is being detached. // Just log the info. - LOG.queuedOperationWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) ); + COLLECTION_LOGGER.queuedOperationWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) ); } } catch (Exception e) { // We don't know why the collection is being detached. // Just log the info. - LOG.queuedOperationWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) ); + COLLECTION_LOGGER.queuedOperationWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) ); } } @@ -772,11 +769,11 @@ else if ( this.session != null ) { ); } else { - LOG.logUnexpectedSessionInCollectionNotConnected( message ); + COLLECTION_LOGGER.logUnexpectedSessionInCollectionNotConnected( message ); } } if ( hasQueuedOperations() ) { - LOG.queuedOperationWhenAttachToSession( collectionInfoString( getRole(), getKey() ) ); + COLLECTION_LOGGER.queuedOperationWhenAttachToSession( collectionInfoString( getRole(), getKey() ) ); } this.session = session; return true; @@ -808,7 +805,7 @@ private String unexpectedSessionStateMessage(SharedSessionContractImplementor se } } // only include the collection contents if debug logging - if ( LOG.isDebugEnabled() ) { + if ( COLLECTION_LOGGER.isDebugEnabled() ) { final String collectionContents = wasInitialized() ? toString() : ""; message.append( "\nCollection contents: [" ).append( collectionContents ).append( "]" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentArrayHolder.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentArrayHolder.java index 15be51b9f15b..655d99d4c6a0 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentArrayHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentArrayHolder.java @@ -5,24 +5,26 @@ package org.hibernate.collection.spi; import java.io.Serializable; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Incubating; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.build.AllowReflection; import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.type.Type; +import static java.lang.reflect.Array.get; +import static java.lang.reflect.Array.getLength; +import static java.lang.reflect.Array.newInstance; +import static java.lang.reflect.Array.set; +import static java.util.Collections.addAll; + /** * A dummy collection wrapper for an array. Lazy initialization is * not supported. The use of arrays to represent persistent @@ -38,8 +40,6 @@ @AllowReflection // We need the ability to create arrays of the same type as in the model. public class PersistentArrayHolder extends AbstractPersistentCollection { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( PersistentArrayHolder.class ); - protected Object array; //just to help out during the load (ugly, i know) @@ -71,16 +71,15 @@ public PersistentArrayHolder(SharedSessionContractImplementor session, Collectio @Override public Serializable getSnapshot(CollectionPersister persister) throws HibernateException { // final int length = (array==null) ? tempList.size() : Array.getLength( array ); - final int length = Array.getLength( array ); - final Serializable result = (Serializable) Array.newInstance( persister.getElementClass(), length ); + final int length = getLength( array ); + final var result = (Serializable) newInstance( persister.getElementClass(), length ); for ( int i=0; i getOrphans(Serializable snapshot, String entityName) throws HibernateException { + //noinspection unchecked + final E[] sn = (E[]) snapshot; final Object[] arr = (Object[]) array; if ( arr.length == 0 ) { return Arrays.asList( sn ); } - final ArrayList result = new ArrayList(); - Collections.addAll( result, sn ); - for ( int i=0; i result = new ArrayList<>(); + addAll( result, sn ); + for ( int i = 0; i < sn.length; i++ ) { + identityRemove( result, arr[i], entityName, getSession() ); + } + return result; } - return result; } @Override public void initializeEmptyCollection(CollectionPersister persister) { assert array == null; - array = Array.newInstance( persister.getElementClass(), 0 ); + array = newInstance( persister.getElementClass(), 0 ); persister.getAttributeMapping().getPropertyAccess().getSetter().set( getOwner(), array ); endRead(); } @@ -119,12 +121,12 @@ public void initializeEmptyCollection(CollectionPersister persister) { public void injectLoadedState(PluralAttributeMapping attributeMapping, List loadingState) { assert isInitializing(); if ( loadingState == null ) { - array = Array.newInstance( elementClass, 0 ); + array = newInstance( elementClass, 0 ); } else { - array = Array.newInstance( elementClass, loadingState.size() ); + array = newInstance( elementClass, loadingState.size() ); for ( int i = 0; i < loadingState.size(); i++ ) { - Array.set( array, i, loadingState.get( i ) ); + set( array, i, loadingState.get( i ) ); } } attributeMapping.getPropertyAccess().getSetter().set( getOwner(), array ); @@ -142,14 +144,14 @@ public boolean isWrapper(Object collection) { @Override public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException { - final Type elementType = persister.getElementType(); - final Serializable snapshot = getSnapshot(); - final int xlen = Array.getLength( snapshot ); - if ( xlen!= Array.getLength( array ) ) { + final var elementType = persister.getElementType(); + final var snapshot = getSnapshot(); + final int length = getLength( snapshot ); + if ( length!= getLength( array ) ) { return false; } - for ( int i=0; i elements() { + final int length = getLength( array ); + final List list = new ArrayList<>( length ); for ( int i=0; i entries(CollectionPersister persister) { return elements(); } @@ -195,22 +196,20 @@ public boolean isDirectlyAccessible() { @Override public void initializeFromCache(CollectionPersister persister, Object disassembled, Object owner) throws HibernateException { - final Serializable[] cached = (Serializable[]) disassembled; - array = Array.newInstance( persister.getElementClass(), cached.length ); - + final var cached = (Serializable[]) disassembled; + array = newInstance( persister.getElementClass(), cached.length ); for ( int i=0; i getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException { final List deletes = new ArrayList<>(); - final Serializable sn = getSnapshot(); - final int snSize = Array.getLength( sn ); - final int arraySize = Array.getLength( array ); - int end; - if ( snSize > arraySize ) { - for ( int i=arraySize; i arraySize ) { + for ( int i=arraySize; i getDeletes(CollectionPersister persister, boolean indexIsForm @Override public boolean hasDeletes(CollectionPersister persister) throws HibernateException { - final Serializable sn = getSnapshot(); - final int snSize = Array.getLength( sn ); - final int arraySize = Array.getLength( array ); - if ( snSize > arraySize ) { + final var snapshot = getSnapshot(); + final int length = getLength( snapshot ); + final int arraySize = getLength( array ); + if ( length > arraySize ) { return true; } - for ( int i=0; i= Array.getLength( sn ) || Array.get( sn, i ) == null ); + final var snapshot = getSnapshot(); + return get( array, i ) != null + && ( i >= getLength( snapshot ) || get( snapshot, i ) == null ); } @Override public boolean needsUpdating(Object entry, int i, Type elemType) throws HibernateException { - final Serializable sn = getSnapshot(); - return i < Array.getLength( sn ) - && Array.get( sn, i ) != null - && Array.get( array, i ) != null - && elemType.isDirty( Array.get( array, i ), Array.get( sn, i ), getSession() ); + final var snapshot = getSnapshot(); + return i < getLength( snapshot ) + && get( snapshot, i ) != null + && get( array, i ) != null + && elemType.isDirty( get( array, i ), get( snapshot, i ), getSession() ); } @Override @@ -286,8 +286,8 @@ public Object getElement(Object entry) { @Override public Object getSnapshotElement(Object entry, int i) { - final Serializable sn = getSnapshot(); - return Array.get( sn, i ); + final var snapshot = getSnapshot(); + return get( snapshot, i ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/PersistenceContextLogging.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/PersistenceContextLogging.java new file mode 100644 index 000000000000..d10fd1fedd73 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/PersistenceContextLogging.java @@ -0,0 +1,86 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.engine.internal; + +import org.hibernate.Internal; +import org.hibernate.internal.log.SubSystemLogging; + +import org.jboss.logging.BasicLogger; +import org.jboss.logging.Logger; +import org.jboss.logging.annotations.LogMessage; +import org.jboss.logging.annotations.Message; +import org.jboss.logging.annotations.MessageLogger; +import org.jboss.logging.annotations.ValidIdRange; + +import java.lang.invoke.MethodHandles; + +import static org.jboss.logging.Logger.Level.DEBUG; +import static org.jboss.logging.Logger.Level.TRACE; +import static org.jboss.logging.Logger.Level.WARN; + +/** + * Sub-system logging related to PersistenceContext runtime events + */ +@SubSystemLogging( + name = PersistenceContextLogging.NAME, + description = "Logging related to persistence context operations and serialization" +) +@MessageLogger(projectCode = "HHH") +@ValidIdRange(min = 90031001, max = 90032000) +@Internal +public interface PersistenceContextLogging extends BasicLogger { + String NAME = SubSystemLogging.BASE + ".persistenceContext"; + + PersistenceContextLogging PERSISTENCE_CONTEXT_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), PersistenceContextLogging.class, NAME ); + + @LogMessage(level = TRACE) + @Message("Setting proxy identifier: %s") + void settingProxyIdentifier(Object id); + + @LogMessage(level = WARN) + @Message("Narrowing proxy to %s - this operation breaks ==") + void narrowingProxy(Class concreteProxyClass); + + @LogMessage(level = TRACE) + @Message("Serializing persistence context") + void serializingPersistenceContext(); + + @LogMessage(level = TRACE) + @Message("Deserializing persistence context") + void deserializingPersistenceContext(); + + @LogMessage(level = TRACE) + @Message("Encountered pruned proxy") + void encounteredPrunedProxy(); + + @LogMessage(level = TRACE) + @Message("Starting serialization of [%s] %s entries") + void startingSerializationOfEntries(int count, String keysName); + + @LogMessage(level = TRACE) + @Message("Starting deserialization of [%s] %s entries") + void startingDeserializationOfEntries(int count, String keysName); + + // Merge and reachability logs (DEBUG/TRACE variants matching existing usage) + @LogMessage(level = TRACE) + @Message("Detached object being merged (corresponding with a managed entity) has a collection that [%s] the detached child") + void detachedManagedContainsChild(String containsOrNot); + + @LogMessage(level = DEBUG) + @Message("Detached proxy being merged has a collection that [%s] the managed child") + void detachedProxyContainsManagedChild(String containsOrNot); + + @LogMessage(level = DEBUG) + @Message("Detached proxy being merged has a collection that [%s] the detached child being merged") + void detachedProxyContainsDetachedChild(String containsOrNot); + + @LogMessage(level = DEBUG) + @Message("A detached object being merged (corresponding to a parent in parentsByChild) has an indexed collection that [%s] the detached child being merged. ") + void detachedParentIndexedContainsDetachedChild(String containsOrNot); + + @LogMessage(level = DEBUG) + @Message("A detached object being merged (corresponding to a managed entity) has an indexed collection that [%s] the detached child being merged. ") + void detachedManagedIndexedContainsDetachedChild(String containsOrNot); +} diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java index b589171250fb..4731c5ba9075 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java @@ -49,8 +49,6 @@ import org.hibernate.event.service.spi.EventListenerGroup; import org.hibernate.event.spi.PostLoadEvent; import org.hibernate.event.spi.PostLoadEventListener; -import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.collections.InstanceIdentityMap; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; @@ -71,6 +69,7 @@ import static org.hibernate.engine.internal.ManagedTypeHelper.asManagedEntity; import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable; import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable; +import static org.hibernate.engine.internal.PersistenceContextLogging.PERSISTENCE_CONTEXT_LOGGER; import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize; import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize; import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer; @@ -88,8 +87,6 @@ */ class StatefulPersistenceContext implements PersistenceContext { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( StatefulPersistenceContext.class ); - private static final int INIT_COLL_SIZE = 8; /* @@ -434,19 +431,21 @@ public boolean containsEntityHolder(EntityKey key) { @Override public void postLoad(JdbcValuesSourceProcessingState processingState, Consumer holderConsumer) { final var callback = processingState.getExecutionContext().getCallback(); - if ( processingState.getLoadingEntityHolders() != null ) { + final var loadingEntityHolders = processingState.getLoadingEntityHolders(); + if ( loadingEntityHolders != null ) { final var listenerGroup = getSession().getFactory().getEventListenerGroups().eventListenerGroup_POST_LOAD; final var postLoadEvent = processingState.getPostLoadEvent(); - for ( final var holder : processingState.getLoadingEntityHolders() ) { + for ( final var holder : loadingEntityHolders ) { processLoadedEntityHolder( holder, listenerGroup, postLoadEvent, callback, holderConsumer ); } - processingState.getLoadingEntityHolders().clear(); + loadingEntityHolders.clear(); } - if ( processingState.getReloadedEntityHolders() != null ) { - for ( final var holder : processingState.getReloadedEntityHolders() ) { + final var reloadedEntityHolders = processingState.getReloadedEntityHolders(); + if ( reloadedEntityHolders != null ) { + for ( final var holder : reloadedEntityHolders ) { processLoadedEntityHolder( holder, null, null, callback, holderConsumer ); } - processingState.getReloadedEntityHolders().clear(); + reloadedEntityHolders.clear(); } } @@ -459,7 +458,8 @@ private void processLoadedEntityHolder( if ( holderConsumer != null ) { holderConsumer.accept( holder ); } - if ( holder.getEntity() == null ) { + final Object entity = holder.getEntity(); + if ( entity == null ) { // It's possible that we tried to load an entity and found out it doesn't exist, // in which case we added an entry with a null proxy and entity. // Remove that empty entry on post load to avoid unwanted side effects @@ -468,13 +468,13 @@ private void processLoadedEntityHolder( else { if ( postLoadEvent != null ) { postLoadEvent.reset(); - postLoadEvent.setEntity( holder.getEntity() ) + postLoadEvent.setEntity( entity ) .setId( holder.getEntityKey().getIdentifier() ) .setPersister( holder.getDescriptor() ); listenerGroup.fireEventOnEachListener( postLoadEvent, PostLoadEventListener::onPostLoad ); } if ( callback != null ) { - callback.invokeAfterLoadActions( holder.getEntity(), holder.getDescriptor(), getSession() ); + callback.invokeAfterLoadActions( entity, holder.getDescriptor(), getSession() ); } holder.resetEntityInitialier(); } @@ -538,22 +538,7 @@ public Object removeEntity(EntityKey key) { } private EntityHolderImpl removeHolder(EntityKey key) { - final EntityHolderImpl holder; - if ( entitiesByKey != null ) { - holder = entitiesByKey.remove( key ); - if ( entitiesByUniqueKey != null ) { - final Object entity = holder == null ? null : holder.entity; - final var itr = entitiesByUniqueKey.values().iterator(); - while ( itr.hasNext() ) { - if ( itr.next() == entity ) { - itr.remove(); - } - } - } - } - else { - holder = null; - } + final var holder = findHolder( key ); // Clear all parent cache parentsByChild = null; @@ -571,6 +556,25 @@ private EntityHolderImpl removeHolder(EntityKey key) { return holder; } + private EntityHolderImpl findHolder(EntityKey key) { + if ( entitiesByKey != null ) { + final var holder = entitiesByKey.remove( key ); + if ( entitiesByUniqueKey != null ) { + final Object entity = holder == null ? null : holder.entity; + final var itr = entitiesByUniqueKey.values().iterator(); + while ( itr.hasNext() ) { + if ( itr.next() == entity ) { + itr.remove(); + } + } + } + return holder; + } + else { + return null; + } + } + @Override public Object getEntity(EntityUniqueKey euk) { return entitiesByUniqueKey == null ? null : entitiesByUniqueKey.get( euk ); @@ -615,8 +619,8 @@ public EntityEntry addEntity( final boolean existsInDatabase, final EntityPersister persister, final boolean disableVersionIncrement) { - final EntityHolder entityHolder = addEntityHolder( entityKey, entity ); - final EntityEntry entityEntry = addEntry( + final var entityHolder = addEntityHolder( entityKey, entity ); + final var entityEntry = addEntry( entity, status, loadedState, @@ -645,7 +649,7 @@ public EntityEntry addEntry( final EntityPersister persister, final boolean disableVersionIncrement) { assert lockMode != null; - final EntityEntry entityEntry = + final var entityEntry = new EntityEntryImpl( status, loadedState, @@ -667,7 +671,7 @@ public EntityEntry addEntry( public EntityEntry addReferenceEntry( final Object entity, final Status status) { - final EntityEntry entityEntry = asManagedEntity( entity ).$$_hibernate_getEntityEntry(); + final var entityEntry = asManagedEntity( entity ).$$_hibernate_getEntityEntry(); entityEntry.setStatus( status ); entityEntryContext.addEntityEntry( entity, entityEntry ); setHasNonReadOnlyEnties( status ); @@ -720,7 +724,7 @@ public boolean reassociateIfUninitializedProxy(Object value) throws MappingExcep public void reassociateProxy(Object value, Object id) throws MappingException { final var lazyInitializer = extractLazyInitializer( value ); if ( lazyInitializer != null ) { - LOG.tracef( "Setting proxy identifier: %s", id ); + PERSISTENCE_CONTEXT_LOGGER.settingProxyIdentifier( id ); lazyInitializer.setIdentifier( id ); reassociateProxy( lazyInitializer, asHibernateProxy( value ) ); } @@ -806,11 +810,11 @@ public void checkUniqueness(EntityKey key, Object object) throws HibernateExcept public Object narrowProxy(Object proxy, EntityPersister persister, EntityKey key, Object object) throws HibernateException { - final Class concreteProxyClass = persister.getConcreteProxyClass(); + final var concreteProxyClass = persister.getConcreteProxyClass(); final boolean alreadyNarrow = concreteProxyClass.isInstance( proxy ); if ( !alreadyNarrow ) { - LOG.narrowingProxy( concreteProxyClass ); + PERSISTENCE_CONTEXT_LOGGER.narrowingProxy( concreteProxyClass ); // If an impl is passed, there is really no point in creating a proxy. // It would just be extra processing. Just return the impl @@ -962,15 +966,15 @@ public Object getCollectionOwner(Object key, CollectionPersister collectionPersi @Override public Object getLoadedCollectionOwnerOrNull(PersistentCollection collection) { - final var ce = getCollectionEntry( collection ); - if ( ce == null || ce.getLoadedPersister() == null ) { + final var collectionEntry = getCollectionEntry( collection ); + if ( collectionEntry == null || collectionEntry.getLoadedPersister() == null ) { return null; } else { // TODO: an alternative is to check if the owner has changed; if it hasn't then // return collection.getOwner() - final Object entityId = getLoadedCollectionOwnerIdOrNull( ce ); - return entityId != null ? getCollectionOwner( entityId, ce.getLoadedPersister() ) : null; + final Object entityId = getLoadedCollectionOwnerIdOrNull( collectionEntry ); + return entityId != null ? getCollectionOwner( entityId, collectionEntry.getLoadedPersister() ) : null; } } @@ -982,27 +986,29 @@ public Object getLoadedCollectionOwnerIdOrNull(PersistentCollection collectio /** * Get the ID for the entity that owned this persistent collection when it was loaded * - * @param ce The collection entry + * @param collectionEntry The collection entry * @return the owner ID if available from the collection's loaded key; otherwise, returns null */ - private Object getLoadedCollectionOwnerIdOrNull(CollectionEntry ce) { - if ( ce == null || ce.getLoadedKey() == null || ce.getLoadedPersister() == null ) { + private Object getLoadedCollectionOwnerIdOrNull(CollectionEntry collectionEntry) { + if ( collectionEntry == null + || collectionEntry.getLoadedKey() == null + || collectionEntry.getLoadedPersister() == null ) { return null; } else { // TODO: an alternative is to check if the owner has changed; if it hasn't then // get the ID from collection.getOwner() - return ce.getLoadedPersister().getCollectionType() - .getIdOfOwnerOrNull( ce.getLoadedKey(), session ); + return collectionEntry.getLoadedPersister().getCollectionType() + .getIdOfOwnerOrNull( collectionEntry.getLoadedKey(), session ); } } @Override public void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Object id) { - final var ce = new CollectionEntry( collection, persister, id, flushing ); - addCollection( collection, ce, id ); + final var collectionEntry = new CollectionEntry( collection, persister, id, flushing ); + addCollection( collection, collectionEntry, id ); if ( session.getLoadQueryInfluencers().effectivelyBatchLoadable( persister ) ) { - getBatchFetchQueue().addBatchLoadableCollection( collection, ce ); + getBatchFetchQueue().addBatchLoadableCollection( collection, collectionEntry ); } } @@ -1010,10 +1016,10 @@ public void addUninitializedCollection(CollectionPersister persister, Persistent public void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection collection) { final Object key = collection.getKey(); assert key != null; - final var ce = new CollectionEntry( persister, key ); - addCollection( collection, ce, key ); + final var collectionEntry = new CollectionEntry( persister, key ); + addCollection( collection, collectionEntry, key ); if ( session.getLoadQueryInfluencers().effectivelyBatchLoadable( persister ) ) { - getBatchFetchQueue().addBatchLoadableCollection( collection, ce ); + getBatchFetchQueue().addBatchLoadableCollection( collection, collectionEntry ); } } @@ -1085,8 +1091,7 @@ private void putCollectionEntry(PersistentCollection collection, CollectionEn * @param persister The collection persister */ private void addCollection(PersistentCollection collection, CollectionPersister persister) { - final var ce = new CollectionEntry( persister, collection ); - putCollectionEntry( collection, ce ); + putCollectionEntry( collection, new CollectionEntry( persister, collection ) ); } @Override @@ -1097,18 +1102,17 @@ public void addInitializedDetachedCollection(CollectionPersister collectionPersi addCollection( collection, collectionPersister ); } else { - final var ce = new CollectionEntry( collection, session.getFactory() ); - addCollection( collection, ce, collection.getKey() ); + addCollection( collection, new CollectionEntry( collection, session.getFactory() ), collection.getKey() ); } } @Override public CollectionEntry addInitializedCollection(CollectionPersister persister, PersistentCollection collection, Object id) throws HibernateException { - final var ce = new CollectionEntry( collection, persister, id, flushing ); - ce.postInitialize( collection, session ); - addCollection( collection, ce, id ); - return ce; + final var collectionEntry = new CollectionEntry( collection, persister, id, flushing ); + collectionEntry.postInitialize( collection, session ); + addCollection( collection, collectionEntry, id ); + return collectionEntry; } @Override @@ -1509,9 +1513,8 @@ && isFoundInParent( propertyName, childEntity, persister, collectionPersister, p collectionPersister, unmergedInstance ); - LOG.tracef( - "Detached object being merged (corresponding with a managed entity) has a collection that [%s] the detached child", - ( found ? "contains" : "does not contain" ) + PERSISTENCE_CONTEXT_LOGGER.detachedManagedContainsChild( + ( found ? "contains" : "does not contain" ) ); } } @@ -1540,9 +1543,8 @@ && isFoundInParent( propertyName, childEntity, persister, collectionPersister, p collectionPersister, mergeMap.get( proxy ) ); - LOG.debugf( - "Detached proxy being merged has a collection that [%s] the managed child", - (found ? "contains" : "does not contain") + PERSISTENCE_CONTEXT_LOGGER.detachedProxyContainsManagedChild( + (found ? "contains" : "does not contain") ); if ( !found ) { found = isFoundInParent( @@ -1552,9 +1554,8 @@ && isFoundInParent( propertyName, childEntity, persister, collectionPersister, p collectionPersister, mergeMap.get( proxy ) ); - LOG.debugf( - "Detached proxy being merged has a collection that [%s] the detached child being merged", - (found ? "contains" : "does not contain") + PERSISTENCE_CONTEXT_LOGGER.detachedProxyContainsDetachedChild( + (found ? "contains" : "does not contain") ); } if ( found ) { @@ -1583,8 +1584,8 @@ private boolean isFoundInParent( Object potentialParent) { final Object collection = persister.getPropertyValue( potentialParent, property ); return collection != null - && Hibernate.isInitialized( collection ) - && collectionPersister.getCollectionType().contains( collection, childEntity, session ); + && Hibernate.isInitialized( collection ) + && collectionPersister.getCollectionType().contains( collection, childEntity, session ); } @Override @@ -1594,7 +1595,7 @@ public Object getIndexInOwner(String entity, String property, Object childEntity final var cp = metamodel.getCollectionDescriptor( entity + '.' + property ); //Extracted as we're logging within two hot loops - final boolean debugEnabled = LOG.isDebugEnabled(); + final boolean debugEnabled = PERSISTENCE_CONTEXT_LOGGER.isDebugEnabled(); // try cache lookup first final Object parent = getParentsByChild( childEntity ); @@ -1609,10 +1610,8 @@ public Object getIndexInOwner(String entity, String property, Object childEntity if ( unMergedInstance != null && unMergedChild != null ) { index = getIndexInParent( property, unMergedChild, persister, cp, unMergedInstance ); if ( debugEnabled ) { - LOG.debugf( - "A detached object being merged (corresponding to a parent in parentsByChild) has an indexed collection that [%s] the detached child being merged. ", - ( index != null ? "contains" : "does not contain" ) - ); + PERSISTENCE_CONTEXT_LOGGER.detachedParentIndexedContainsDetachedChild( + index != null ? "contains" : "does not contain" ); } } } @@ -1627,11 +1626,10 @@ public Object getIndexInOwner(String entity, String property, Object childEntity } //Not found in cache, proceed - for ( var me : reentrantSafeEntityEntries() ) { - final EntityEntry ee = me.getValue(); - if ( persister.isSubclassEntityName( ee.getEntityName() ) ) { - final Object instance = me.getKey(); - + for ( var entry : reentrantSafeEntityEntries() ) { + final var entityEntry = entry.getValue(); + if ( persister.isSubclassEntityName( entityEntry.getEntityName() ) ) { + final Object instance = entry.getKey(); Object index = getIndexInParent( property, childEntity, persister, cp, instance ); if ( index==null && mergeMap!=null ) { final Object unMergedInstance = mergeMap.get( instance ); @@ -1639,10 +1637,8 @@ public Object getIndexInOwner(String entity, String property, Object childEntity if ( unMergedInstance != null && unMergedChild!=null ) { index = getIndexInParent( property, unMergedChild, persister, cp, unMergedInstance ); if ( debugEnabled ) { - LOG.debugf( - "A detached object being merged (corresponding to a managed entity) has an indexed collection that [%s] the detached child being merged. ", - (index != null ? "contains" : "does not contain" ) - ); + PERSISTENCE_CONTEXT_LOGGER.detachedManagedIndexedContainsDetachedChild( + index != null ? "contains" : "does not contain" ); } } } @@ -1797,7 +1793,7 @@ public void replaceEntityEntryRowId(Object entity, Object rowId) { * @throws IOException serialization errors. */ public void serialize(ObjectOutputStream oos) throws IOException { - LOG.trace( "Serializing persistence context" ); + PERSISTENCE_CONTEXT_LOGGER.serializingPersistenceContext(); oos.writeBoolean( defaultReadOnly ); oos.writeBoolean( hasNonReadOnlyEntities ); @@ -1878,10 +1874,9 @@ private void writeCollectionToStream( oos.writeInt( 0 ); } else { - oos.writeInt( collection.size() ); - if ( LOG.isTraceEnabled() ) { - LOG.trace( "Starting serialization of [" + collection.size() + "] " + keysName + " entries" ); - } + final int size = collection.size(); + oos.writeInt( size ); + PERSISTENCE_CONTEXT_LOGGER.startingSerializationOfEntries( size, keysName ); for ( E entry : collection ) { serializer.serialize( entry, oos ); } @@ -1902,7 +1897,7 @@ private void writeCollectionToStream( public static StatefulPersistenceContext deserialize( ObjectInputStream ois, SessionImplementor session) throws IOException, ClassNotFoundException { - LOG.trace( "Deserializing persistence context" ); + PERSISTENCE_CONTEXT_LOGGER.deserializingPersistenceContext(); final var rtn = new StatefulPersistenceContext( session ); final var sfi = session.getFactory(); @@ -1917,9 +1912,9 @@ public static StatefulPersistenceContext deserialize( rtn.hasNonReadOnlyEntities = ois.readBoolean(); int count = ois.readInt(); - final boolean traceEnabled = LOG.isTraceEnabled(); + final boolean traceEnabled = PERSISTENCE_CONTEXT_LOGGER.isTraceEnabled(); if ( traceEnabled ) { - LOG.trace( "Starting deserialization of [" + count + "] entitiesByUniqueKey entries" ); + PERSISTENCE_CONTEXT_LOGGER.startingDeserializationOfEntries( count, "entitiesByUniqueKey" ); } if ( count != 0 ) { rtn.entitiesByUniqueKey = mapOfSize(Math.max(count, INIT_COLL_SIZE)); @@ -1930,7 +1925,7 @@ public static StatefulPersistenceContext deserialize( count = ois.readInt(); if ( traceEnabled ) { - LOG.trace( "Starting deserialization of [" + count + "] entitySnapshotsByKey entries" ); + PERSISTENCE_CONTEXT_LOGGER.startingDeserializationOfEntries( count, "entitySnapshotsByKey" ); } rtn.entitySnapshotsByKey = mapOfSize(Math.max(count, INIT_COLL_SIZE)); for ( int i = 0; i < count; i++ ) { @@ -1941,7 +1936,7 @@ public static StatefulPersistenceContext deserialize( count = ois.readInt(); if ( traceEnabled ) { - LOG.trace( "Starting deserialization of [" + count + "] entitiesByKey entries" ); + PERSISTENCE_CONTEXT_LOGGER.startingDeserializationOfEntries( count, "entitiesByKey" ); } rtn.entitiesByKey = mapOfSize(Math.max(count, INIT_COLL_SIZE)); final var metamodel = sfi.getMappingMetamodel(); @@ -1962,7 +1957,7 @@ public static StatefulPersistenceContext deserialize( else { // otherwise, the proxy was pruned during the serialization process if ( traceEnabled ) { - LOG.trace( "Encountered pruned proxy" ); + PERSISTENCE_CONTEXT_LOGGER.encounteredPrunedProxy(); } } } @@ -1972,7 +1967,7 @@ public static StatefulPersistenceContext deserialize( count = ois.readInt(); if ( traceEnabled ) { - LOG.trace( "Starting deserialization of [" + count + "] collectionsByKey entries" ); + PERSISTENCE_CONTEXT_LOGGER.startingDeserializationOfEntries( count, "collectionsByKey" ); } rtn.collectionsByKey = mapOfSize(Math.max(count, INIT_COLL_SIZE)); for ( int i = 0; i < count; i++ ) { @@ -1984,7 +1979,7 @@ public static StatefulPersistenceContext deserialize( count = ois.readInt(); if ( traceEnabled ) { - LOG.trace( "Starting deserialization of [" + count + "] collectionEntries entries" ); + PERSISTENCE_CONTEXT_LOGGER.startingDeserializationOfEntries( count, "collectionEntries" ); } for ( int i = 0; i < count; i++ ) { final var pc = (PersistentCollection) ois.readObject(); @@ -1995,7 +1990,7 @@ public static StatefulPersistenceContext deserialize( count = ois.readInt(); if ( traceEnabled ) { - LOG.trace( "Starting deserialization of [" + count + "] arrayHolders entries" ); + PERSISTENCE_CONTEXT_LOGGER.startingDeserializationOfEntries( count, "arrayHolders" ); } if ( count != 0 ) { rtn.arrayHolders = new IdentityHashMap<>(Math.max(count, INIT_COLL_SIZE)); @@ -2006,7 +2001,7 @@ public static StatefulPersistenceContext deserialize( count = ois.readInt(); if ( traceEnabled ) { - LOG.trace( "Starting deserialization of [" + count + "] nullifiableEntityKey entries" ); + PERSISTENCE_CONTEXT_LOGGER.startingDeserializationOfEntries( count, "nullifiableEntityKey" ); } rtn.nullifiableEntityKeys = new HashSet<>(); for ( int i = 0; i < count; i++ ) { @@ -2014,8 +2009,8 @@ public static StatefulPersistenceContext deserialize( } count = ois.readInt(); - if ( LOG.isTraceEnabled() ) { - LOG.trace( "Starting deserialization of [" + count + "] deletedUnloadedEntityKeys entries" ); + if ( PERSISTENCE_CONTEXT_LOGGER.isTraceEnabled() ) { + PERSISTENCE_CONTEXT_LOGGER.startingDeserializationOfEntries( count, "deletedUnloadedEntityKeys" ); } rtn.deletedUnloadedEntityKeys = new HashSet<>(); for ( int i = 0; i < count; i++ ) { @@ -2153,11 +2148,11 @@ public void clearCollectionsByKey() { } @Override - public PersistentCollection addCollectionByKey(CollectionKey collectionKey, PersistentCollection persistentCollection) { + public PersistentCollection addCollectionByKey(CollectionKey collectionKey, PersistentCollection collection) { if ( collectionsByKey == null ) { collectionsByKey = mapOfSize( INIT_COLL_SIZE ); } - return collectionsByKey.put( collectionKey, persistentCollection ); + return collectionsByKey.put( collectionKey, collection ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index f3394dde6168..ff7878d729ff 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -137,10 +137,6 @@ void expectedType(String name, @Message(value = "Instantiating explicit connection provider: %s", id = 130) void instantiatingExplicitConnectionProvider(String providerClassName); - @LogMessage(level = ERROR) - @Message(value = "Array element type error\n%s", id = 132) - void invalidArrayElementType(String message); - @LogMessage(level = INFO) @Message(value = "java.sql.Types mapped the same code [%s] multiple times; was [%s]; now [%s]", id = 141) void JavaSqlTypesMappedSameCodeMultipleTimes(int code, String old, String name); @@ -281,10 +277,6 @@ void missingArguments( @Message(value = "Could not close stream on hibernate.properties: %s", id = 297) void unableToCloseStreamError(IOException error); - @LogMessage(level = WARN) - @Message(value = "Unable to close temporary session used to load lazy collection associated to no session", id = 303) - void unableToCloseTemporarySession(); - @LogMessage(level = WARN) @Message(value = "Could not copy system properties, system properties will be ignored", id = 304) void unableToCopySystemProperties(); @@ -450,14 +442,6 @@ void cannotResolveNonNullableTransientDependencies( @Message(value = "Creating pooled optimizer (lo) with [incrementSize=%s; returnClass=%s]", id = 467) void creatingPooledLoOptimizer(int incrementSize, String name); - @LogMessage(level = WARN) - @Message(value = "An unexpected session is defined for a collection, but the collection is not connected to that session. A persistent collection may only be associated with one session at a time. Overwriting session. %s", id = 470) - void logUnexpectedSessionInCollectionNotConnected(String msg); - - @LogMessage(level = WARN) - @Message(value = "Cannot unset session in a collection because an unexpected session is defined. A persistent collection may only be associated with one session at a time. %s", id = 471 ) - void logCannotUnsetUnexpectedSessionInCollection(String msg); - @LogMessage(level = INFO) @Message(value = "Omitting cached file [%s] as the mapping file is newer", id = 473) void cachedFileObsolete(File cachedFile); @@ -513,18 +497,6 @@ void cannotResolveNonNullableTransientDependencies( @Message(value = "Attempt to merge an uninitialized collection with queued operations; queued operations will be ignored: %s", id = 494) void ignoreQueuedOperationsOnMerge(String collectionInfoString); - @LogMessage(level = WARN) - @Message(value = "Attaching an uninitialized collection with queued operations to a session: %s", id = 495) - void queuedOperationWhenAttachToSession(String collectionInfoString); - - @LogMessage(level = INFO) - @Message(value = "Detaching an uninitialized collection with queued operations from a session: %s", id = 496) - void queuedOperationWhenDetachFromSession(String collectionInfoString); - - @LogMessage(level = DEBUG) - @Message(value = "Detaching an uninitialized collection with queued operations from a session due to rollback: %s", id = 498) - void queuedOperationWhenDetachFromSessionOnRollback(String collectionInfoString); - @LogMessage(level = WARN) @Message(value = "The [%s] property of the [%s] entity was modified, but it won't be updated because the property is immutable.", id = 502) void ignoreImmutablePropertyModification(String propertyName, String entityName); @@ -533,10 +505,6 @@ void cannotResolveNonNullableTransientDependencies( @Message(value = "Multiple configuration properties defined to create schema. Choose at most one among 'jakarta.persistence.create-database-schemas' or 'hibernate.hbm2ddl.create_namespaces'.", id = 504) void multipleSchemaCreationSettingsDefined(); - @LogMessage(level = WARN) - @Message(value = "Detaching an uninitialized collection with enabled filters from a session: %s", id = 506) - void enabledFiltersWhenDetachFromSession(String collectionInfoString); - @LogMessage(level = WARN) @Message(value = "Multi-table insert is not available due to missing identity and window function support for: %s", id = 509) void multiTableInsertNotAvailable(String entityName); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/collection/delayedOperation/DetachedBagDelayedOperationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/collection/delayedOperation/DetachedBagDelayedOperationTest.java index 2937e5f928bd..d89dfb94f86e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/collection/delayedOperation/DetachedBagDelayedOperationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/collection/delayedOperation/DetachedBagDelayedOperationTest.java @@ -20,6 +20,7 @@ import jakarta.persistence.OneToMany; import org.hibernate.Hibernate; +import org.hibernate.collection.internal.CollectionLogger; import org.hibernate.collection.spi.AbstractPersistentCollection; import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider; import org.hibernate.type.CollectionType; @@ -67,16 +68,16 @@ loggers = @org.hibernate.testing.orm.junit.Logger( loggerNameClass = CollectionType.class ) ), @LoggingInspections.Message( - messageKey = "HHH000495", - loggers = @org.hibernate.testing.orm.junit.Logger( loggerNameClass = AbstractPersistentCollection.class ) + messageKey = "HHH90030004", + loggers = @org.hibernate.testing.orm.junit.Logger( loggerName = CollectionLogger.NAME ) ), @LoggingInspections.Message( - messageKey = "HHH000496", - loggers = @org.hibernate.testing.orm.junit.Logger( loggerNameClass = AbstractPersistentCollection.class ) + messageKey = "HHH90030005", + loggers = @org.hibernate.testing.orm.junit.Logger( loggerName = CollectionLogger.NAME ) ), @LoggingInspections.Message( - messageKey = "HHH000498", - loggers = @org.hibernate.testing.orm.junit.Logger( loggerNameClass = AbstractPersistentCollection.class ) + messageKey = "HHH90030006", + loggers = @org.hibernate.testing.orm.junit.Logger( loggerName = CollectionLogger.NAME ) ) } ) @@ -122,9 +123,9 @@ public void testMergeDetachedCollectionWithQueuedOperations( ); final MessageKeyWatcher opMergedWatcher = loggingScope.getWatcher( "HHH000494", CollectionType.class ); - final MessageKeyWatcher opAttachedWatcher = loggingScope.getWatcher( "HHH000495", AbstractPersistentCollection.class ); - final MessageKeyWatcher opDetachedWatcher = loggingScope.getWatcher( "HHH000496", AbstractPersistentCollection.class ); - final MessageKeyWatcher opRollbackWatcher = loggingScope.getWatcher( "HHH000498", AbstractPersistentCollection.class ); + final MessageKeyWatcher opAttachedWatcher = loggingScope.getWatcher( "HHH90030004", CollectionLogger.NAME ); + final MessageKeyWatcher opDetachedWatcher = loggingScope.getWatcher( "HHH90030005", CollectionLogger.NAME ); + final MessageKeyWatcher opRollbackWatcher = loggingScope.getWatcher( "HHH90030006", CollectionLogger.NAME ); final Parent pWithQueuedOperations = scope.fromTransaction( session -> { @@ -145,10 +146,6 @@ public void testMergeDetachedCollectionWithQueuedOperations( session.detach( p ); assertTrue( opDetachedWatcher.wasTriggered() ); - assertEquals( - "HHH000496: Detaching an uninitialized collection with queued operations from a session: [org.hibernate.orm.test.collection.delayedOperation.DetachedBagDelayedOperationTest$Parent.children with owner id '1']", - opDetachedWatcher.getFirstTriggeredMessage() - ); opDetachedWatcher.reset(); // Make sure nothing else got triggered @@ -182,10 +179,6 @@ public void testMergeDetachedCollectionWithQueuedOperations( assertFalse( opMergedWatcher.wasTriggered() ); Parent p = session.merge( pWithQueuedOperations ); assertTrue( opMergedWatcher.wasTriggered() ); - assertEquals( - "HHH000494: Attempt to merge an uninitialized collection with queued operations; queued operations will be ignored: [org.hibernate.orm.test.collection.delayedOperation.DetachedBagDelayedOperationTest$Parent.children with owner id '1']", - opMergedWatcher.getFirstTriggeredMessage() - ); opMergedWatcher.reset(); assertFalse( Hibernate.isInitialized( p.getChildren() ) ); @@ -217,9 +210,9 @@ public void testCollectionWithQueuedOperationsOnRollback( SessionFactoryScope scope, LoggingInspectionsScope loggingScope) { final MessageKeyWatcher opMergedWatcher = loggingScope.getWatcher( "HHH000494", CollectionType.class ); - final MessageKeyWatcher opAttachedWatcher = loggingScope.getWatcher( "HHH000495", AbstractPersistentCollection.class ); - final MessageKeyWatcher opDetachedWatcher = loggingScope.getWatcher( "HHH000496", AbstractPersistentCollection.class ); - final MessageKeyWatcher opRollbackWatcher = loggingScope.getWatcher( "HHH000498", AbstractPersistentCollection.class ); + final MessageKeyWatcher opAttachedWatcher = loggingScope.getWatcher( "HHH90030004", CollectionLogger.NAME ); + final MessageKeyWatcher opDetachedWatcher = loggingScope.getWatcher( "HHH90030005", CollectionLogger.NAME ); + final MessageKeyWatcher opRollbackWatcher = loggingScope.getWatcher( "HHH90030006", CollectionLogger.NAME ); final Parent pOriginal = scope.fromTransaction( session -> { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/collection/multisession/MultipleSessionCollectionWarningTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/collection/multisession/MultipleSessionCollectionWarningTest.java index 3c3c5f8f5ac9..024e2b5b1131 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/collection/multisession/MultipleSessionCollectionWarningTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/collection/multisession/MultipleSessionCollectionWarningTest.java @@ -14,6 +14,7 @@ import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import org.hibernate.collection.internal.CollectionLogger; import org.hibernate.collection.spi.AbstractPersistentCollection; import org.hibernate.collection.spi.PersistentSet; import org.hibernate.collection.spi.PersistentCollection; @@ -24,7 +25,6 @@ import org.hibernate.testing.orm.junit.Logger; import org.hibernate.testing.orm.junit.LoggingInspections; import org.hibernate.testing.orm.junit.LoggingInspectionsScope; -import org.hibernate.testing.orm.junit.MessageKeyWatcher; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.junit.jupiter.api.Test; @@ -48,12 +48,8 @@ @LoggingInspections( messages = { @LoggingInspections.Message( - messageKey = "HHH000470", - loggers = @Logger( loggerNameClass = AbstractPersistentCollection.class ) - ), - @LoggingInspections.Message( - messageKey = "HHH000471", - loggers = @Logger( loggerNameClass = AbstractPersistentCollection.class ) + messageKey = "HHH90030007", + loggers = @Logger(loggerName = CollectionLogger.NAME) ) } ) @@ -90,7 +86,7 @@ public void testUnsetSessionCannotOverwriteNonConnectedSession( s2 -> { s2.getTransaction().begin(); try { - final MessageKeyWatcher watcher = loggingScope.getWatcher( "HHH000471", AbstractPersistentCollection.class ); + final var watcher = loggingScope.getWatcher( "HHH90030007", CollectionLogger.NAME ); assertFalse( watcher.wasTriggered() ); // The following should trigger warning because we're unsetting a different session. @@ -145,7 +141,7 @@ public void testUnsetSessionCannotOverwriteConnectedSession( s2 -> { s2.getTransaction().begin(); try { - final MessageKeyWatcher watcher = loggingScope.getWatcher( "HHH000471", AbstractPersistentCollection.class ); + final var watcher = loggingScope.getWatcher( "HHH90030007", CollectionLogger.NAME ); assertFalse( watcher.wasTriggered() ); // The following should trigger warning because we're unsetting a different session @@ -200,7 +196,7 @@ public void testUnsetSessionCannotOverwriteConnectedSessionFlushed( s2 -> { s2.getTransaction().begin(); try { - final MessageKeyWatcher watcher = loggingScope.getWatcher( "HHH000471", AbstractPersistentCollection.class ); + final var watcher = loggingScope.getWatcher( "HHH90030007", CollectionLogger.NAME ); assertFalse( watcher.wasTriggered() ); // The following should trigger warning because we're unsetting a different session diff --git a/hibernate-core/src/test/resources/log4j2.properties b/hibernate-core/src/test/resources/log4j2.properties index bf3f5eca5ca5..0960534771ea 100644 --- a/hibernate-core/src/test/resources/log4j2.properties +++ b/hibernate-core/src/test/resources/log4j2.properties @@ -123,10 +123,10 @@ logger.merged-entity-copies.name=org.hibernate.event.internal.EntityCopyAllowedL logger.scanning-coordinator.name=org.hibernate.orm.boot.scan logger.scanning-coordinator.level=debug -logger.abstract-persistent-collection.name=org.hibernate.collection.spi.AbstractPersistentCollection +logger.abstract-persistent-collection.name=org.hibernate.orm.collection logger.abstract-persistent-collection.level=debug -logger.resource-registry-standard.name=org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl +logger.resource-registry-standard.name=org.hibernate.orm.resource.registry logger.resource-registry-standard.level=debug logger.cache.name=org.hibernate.cache