diff --git a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java index 1bbdaf31de..a1a1634231 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java @@ -189,15 +189,18 @@ public class ManyToOneType extends EntityType { boolean[] checkable, SharedSessionContractImplementor session) throws HibernateException { if ( current == null ) { - return old!=null; + return old != null; } if ( old == null ) { // we already know current is not null... return true; } + + assert current.getClass().isAssignableFrom( old.getClass() ); + // the ids are fully resolved, so compare them with isDirty(), not isModified() return getIdentifierOrUniqueKeyType( session.getFactory() ) - .isDirty( old, getIdentifier( current, session ), session ); + .isDirty( getIdentifier( old, session ), getIdentifier( current, session ), session ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java index a03f47bee9..83f4bd527b 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java @@ -121,10 +121,8 @@ public class OneToOneType extends EntityType { return false; } - Object oldid = getIdentifier( old, session ); - Object newid = getIdentifier( current, session ); - - return getIdentifierType( session ).isDirty( oldid, newid, session ); + return getIdentifierType( session ) + .isDirty( getIdentifier( old, session ), getIdentifier( current, session ), session ); } @Override