improve javadoc for hibernate.event.merge.entity_copy_observer

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-26 18:02:02 +02:00
parent e3cf006e76
commit bbb596b23e
2 changed files with 20 additions and 18 deletions

View File

@ -6,7 +6,6 @@
*/ */
package org.hibernate.cfg; package org.hibernate.cfg;
import org.hibernate.CustomEntityDirtinessStrategy;
import org.hibernate.jpa.LegacySpecHints; import org.hibernate.jpa.LegacySpecHints;
import org.hibernate.jpa.SpecHints; import org.hibernate.jpa.SpecHints;
@ -137,24 +136,30 @@ public interface AvailableSettings
* @since 5.2 * @since 5.2
*/ */
String ALLOW_REFRESH_DETACHED_ENTITY = "hibernate.allow_refresh_detached_entity"; String ALLOW_REFRESH_DETACHED_ENTITY = "hibernate.allow_refresh_detached_entity";
/** /**
* Setting that specifies how Hibernate will respond when multiple representations of * Specifies how Hibernate should behave when multiple representations of the same
* the same persistent entity ("entity copy") are detected while merging. * persistent entity instance, that is, multiple detached objects with the same
* persistent identity, are encountered while cascading a
* {@link org.hibernate.Session#merge(Object) merge()} operation.
* <p> * <p>
* The possible values are: * The possible values are:
* <ul> * <ul>
* <li>disallow (the default): throws {@link IllegalStateException} if an entity * <li>{@code disallow} (the default): throw {@link IllegalStateException} if
* copy is detected * multiple copies of the same entity are encountered
* <li>allow: performs the merge operation on each entity copy that is detected * <li>{@code allow}: perform the merge operation for every copy encountered,
* <li>log: (provided for testing only) performs the merge operation on each entity * making no attempt to reconcile conflicts (this may result in lost updates)
* copy that is detected and logs information about the entity copies. This * <li>{@code log}: (provided for testing only) perform the merge operation for
* setting requires DEBUG logging be enabled for * every copy encountered and log information about the copies. This setting
* requires that {@code DEBUG} logging be enabled for
* {@link org.hibernate.event.internal.EntityCopyAllowedLoggedObserver}. * {@link org.hibernate.event.internal.EntityCopyAllowedLoggedObserver}.
* </ul> * </ul>
* <p> * <p>
* Alternatively, the application may customize the behavior by providing an * Alternatively, the application may customize the behavior by providing a custom
* implementation of {@link org.hibernate.event.spi.EntityCopyObserver} and setting * implementation of {@link org.hibernate.event.spi.EntityCopyObserver} and setting
* the property {@value #MERGE_ENTITY_COPY_OBSERVER} to the class name. * the property {@value #MERGE_ENTITY_COPY_OBSERVER} to the class name. This, in
* principle, allows the application program to specify rules for reconciling
* conflicts.
* <p> * <p>
* When this property is set to {@code allow} or {@code log}, Hibernate will merge * When this property is set to {@code allow} or {@code log}, Hibernate will merge
* each entity copy detected while cascading the merge operation. In the process of * each entity copy detected while cascading the merge operation. In the process of
@ -164,6 +169,8 @@ public interface AvailableSettings
* merging an entity copy will be overwritten when another entity copy is merged. * merging an entity copy will be overwritten when another entity copy is merged.
* *
* @since 4.3 * @since 4.3
*
* @see org.hibernate.event.spi.EntityCopyObserver
*/ */
@SuppressWarnings("JavaDoc") @SuppressWarnings("JavaDoc")
String MERGE_ENTITY_COPY_OBSERVER = "hibernate.event.merge.entity_copy_observer"; String MERGE_ENTITY_COPY_OBSERVER = "hibernate.event.merge.entity_copy_observer";
@ -191,7 +198,7 @@ public interface AvailableSettings
* Setting to identify a {@link org.hibernate.CustomEntityDirtinessStrategy} to use. * Setting to identify a {@link org.hibernate.CustomEntityDirtinessStrategy} to use.
* May specify either a class name or an instance. * May specify either a class name or an instance.
* *
* @see org.hibernate.boot.SessionFactoryBuilder#applyCustomEntityDirtinessStrategy(CustomEntityDirtinessStrategy) * @see org.hibernate.boot.SessionFactoryBuilder#applyCustomEntityDirtinessStrategy
*/ */
String CUSTOM_ENTITY_DIRTINESS_STRATEGY = "hibernate.entity_dirtiness_strategy"; String CUSTOM_ENTITY_DIRTINESS_STRATEGY = "hibernate.entity_dirtiness_strategy";

View File

@ -234,12 +234,7 @@ public class MergeContext implements Map<Object,Object> {
// this is a new mapping for mergeEntity in mergeToManagedEntityXref // this is a new mapping for mergeEntity in mergeToManagedEntityXref
if ( oldMergeEntity != null ) { if ( oldMergeEntity != null ) {
// oldMergeEntity was a different merge entity with the same corresponding managed entity; // oldMergeEntity was a different merge entity with the same corresponding managed entity;
entityCopyObserver.entityCopyDetected( entityCopyObserver.entityCopyDetected( managedEntity, mergeEntity, oldMergeEntity, session );
managedEntity,
mergeEntity,
oldMergeEntity,
session
);
} }
if ( oldOperatedOn != null ) { if ( oldOperatedOn != null ) {
throw new IllegalStateException( throw new IllegalStateException(