Skip to content

Commit e2b44b7

Browse files
committed
HHH-19535 Interceptor.postMerge() should accept an id
1 parent 605c0c1 commit e2b44b7

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

hibernate-core/src/main/java/org/hibernate/Interceptor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,18 @@ default void preMerge(Object entity, Object[] state, String[] propertyNames, Typ
434434
*
435435
* @param source The entity passed to {@code merge()}
436436
* @param target The target managed entity
437+
* @param id The identifier of the managed entity
437438
* @param targetState The copied state already assigned to the target managed entity
438439
* @param originalState The original state of the target managed entity before assignment of the copied state,
439-
* or {@code null} if the target entity is a new instance
440+
* or {@code null} if the target entity is a new instance
440441
* @param propertyNames The names of the entity properties
441442
* @param propertyTypes The types of the entity properties
442443
*
443444
* @since 7.1
444445
*/
445446
@Incubating
446447
default void postMerge(
447-
Object source, Object target,
448+
Object source, Object target, Object id,
448449
Object[] targetState, Object[] originalState,
449450
String[] propertyNames, Type[] propertyTypes) {}
450451
}

hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import org.hibernate.AssertionFailure;
1010
import org.hibernate.HibernateException;
11+
import org.hibernate.Interceptor;
1112
import org.hibernate.ObjectDeletedException;
1213
import org.hibernate.StaleObjectStateException;
1314
import org.hibernate.WrongClassException;
@@ -282,6 +283,7 @@ protected void entityIsTransient(MergeEvent event, Object id, MergeContext copyC
282283

283284
final Object entity = event.getEntity();
284285
final EventSource session = event.getSession();
286+
final Interceptor interceptor = session.getInterceptor();
285287
final String entityName = event.getEntityName();
286288
final EntityPersister persister = session.getEntityPersister( entityName, entity );
287289
final String[] propertyNames = persister.getPropertyNames();
@@ -294,7 +296,7 @@ protected void entityIsTransient(MergeEvent event, Object id, MergeContext copyC
294296
super.cascadeBeforeSave( session, persister, entity, copyCache );
295297

296298
final Object[] sourceValues = persister.getValues( entity );
297-
session.getInterceptor().preMerge( entity, sourceValues, propertyNames, propertyTypes );
299+
interceptor.preMerge( entity, sourceValues, propertyNames, propertyTypes );
298300
final Object[] copiedValues = TypeHelper.replace(
299301
sourceValues,
300302
persister.getValues( copy ),
@@ -326,7 +328,7 @@ protected void entityIsTransient(MergeEvent event, Object id, MergeContext copyC
326328
ForeignKeyDirection.TO_PARENT
327329
);
328330
persister.setValues( copy, targetValues );
329-
session.getInterceptor().postMerge( entity, copy, targetValues, null, propertyNames, propertyTypes );
331+
interceptor.postMerge( entity, copy, id, targetValues, null, propertyNames, propertyTypes );
330332

331333
// saveTransientEntity has been called using a copy that contains empty collections
332334
// (copyValues uses ForeignKeyDirection.FROM_PARENT) then the PC may contain a wrong
@@ -341,9 +343,9 @@ protected void entityIsTransient(MergeEvent event, Object id, MergeContext copyC
341343
event.setResult( copy );
342344

343345
if ( isPersistentAttributeInterceptable( copy ) ) {
344-
final PersistentAttributeInterceptor interceptor =
346+
final PersistentAttributeInterceptor attributeInterceptor =
345347
asPersistentAttributeInterceptable( copy ).$$_hibernate_getInterceptor();
346-
if ( interceptor == null ) {
348+
if ( attributeInterceptor == null ) {
347349
persister.getBytecodeEnhancementMetadata().injectInterceptor( copy, id, session );
348350
}
349351
}
@@ -453,12 +455,13 @@ protected void entityIsDetached(MergeEvent event, Object copiedId, Object origin
453455
// copy created before we actually copy
454456
cascadeOnMerge( session, persister, entity, copyCache );
455457

458+
final Interceptor interceptor = session.getInterceptor();
456459
final String[] propertyNames = persister.getPropertyNames();
457460
final Type[] propertyTypes = persister.getPropertyTypes();
458461

459462
final Object[] sourceValues = persister.getValues( entity );
460463
final Object[] originalValues = persister.getValues( target );
461-
session.getInterceptor().preMerge( entity, sourceValues, propertyNames, propertyTypes );
464+
interceptor.preMerge( entity, sourceValues, propertyNames, propertyTypes );
462465
final Object[] targetValues = TypeHelper.replace(
463466
sourceValues,
464467
originalValues,
@@ -468,7 +471,7 @@ protected void entityIsDetached(MergeEvent event, Object copiedId, Object origin
468471
copyCache
469472
);
470473
persister.setValues( target, targetValues );
471-
session.getInterceptor().postMerge( entity, target, targetValues, originalValues, propertyNames, propertyTypes );
474+
interceptor.postMerge( entity, target, id, targetValues, originalValues, propertyNames, propertyTypes );
472475
//copyValues works by reflection, so explicitly mark the entity instance dirty
473476
markInterceptorDirty( entity, target );
474477
event.setResult( result );

0 commit comments

Comments
 (0)