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) {
|
private Object extractIdentifier(Object entity, SessionFactoryImplementor factory) {
|
||||||
final EntityPersister concretePersister =
|
final EntityPersister concretePersister = getAssociatedEntityPersister( factory );
|
||||||
factory.getMappingMetamodel().getEntityDescriptor( associatedEntityName );
|
|
||||||
return concretePersister == null
|
return concretePersister == null
|
||||||
? null
|
? null
|
||||||
: concretePersister.getIdentifier( entity, null );
|
: concretePersister.getIdentifier( entity, null );
|
||||||
|
@ -345,6 +344,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
||||||
@Override
|
@Override
|
||||||
public int getHashCode(Object x, SessionFactoryImplementor factory) {
|
public int getHashCode(Object x, SessionFactoryImplementor factory) {
|
||||||
final EntityPersister persister = getAssociatedEntityPersister( factory );
|
final EntityPersister persister = getAssociatedEntityPersister( factory );
|
||||||
|
if ( isReferenceToPrimaryKey() ) {
|
||||||
final Object id;
|
final Object id;
|
||||||
final LazyInitializer lazyInitializer = extractLazyInitializer( x );
|
final LazyInitializer lazyInitializer = extractLazyInitializer( x );
|
||||||
if ( lazyInitializer != null ) {
|
if ( lazyInitializer != null ) {
|
||||||
|
@ -361,6 +361,12 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
||||||
}
|
}
|
||||||
return persister.getIdentifierType().getHashCode( id, factory );
|
return persister.getIdentifierType().getHashCode( id, factory );
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
assert uniqueKeyPropertyName != null;
|
||||||
|
final Type keyType = persister.getPropertyType( uniqueKeyPropertyName );
|
||||||
|
return keyType.getHashCode( x, factory );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
|
public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
|
||||||
|
|
Loading…
Reference in New Issue