HHH-18390 Fix hash code for entity types not referring to primary keys
This commit is contained in:
parent
baafcd9fbb
commit
1aa7db6a0a
|
@ -281,8 +281,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
}
|
||||
|
||||
private Object extractIdentifier(Object entity, SessionFactoryImplementor factory) {
|
||||
final EntityPersister concretePersister =
|
||||
factory.getMappingMetamodel().getEntityDescriptor( associatedEntityName );
|
||||
final EntityPersister concretePersister = getAssociatedEntityPersister( factory );
|
||||
return concretePersister == null
|
||||
? null
|
||||
: concretePersister.getIdentifier( entity, null );
|
||||
|
@ -345,6 +344,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
@Override
|
||||
public int getHashCode(Object x, SessionFactoryImplementor factory) {
|
||||
final EntityPersister persister = getAssociatedEntityPersister( factory );
|
||||
if ( isReferenceToPrimaryKey() ) {
|
||||
final Object id;
|
||||
final LazyInitializer lazyInitializer = extractLazyInitializer( x );
|
||||
if ( lazyInitializer != null ) {
|
||||
|
@ -361,6 +361,12 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
}
|
||||
return persister.getIdentifierType().getHashCode( id, factory );
|
||||
}
|
||||
else {
|
||||
assert uniqueKeyPropertyName != null;
|
||||
final Type keyType = persister.getPropertyType( uniqueKeyPropertyName );
|
||||
return keyType.getHashCode( x, factory );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
|
||||
|
|
Loading…
Reference in New Issue