expose two operations on EntityType for use by Hibernate Reactive

see https://github.com/hibernate/hibernate-reactive/pull/954
This commit is contained in:
Gavin King 2021-09-05 14:08:23 +02:00 committed by Sanne Grinovero
parent 3810727f5d
commit 971a47d15d
1 changed files with 11 additions and 9 deletions

View File

@ -488,7 +488,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
return getAssociatedEntityPersister( factory ).getIdentifierType(); return getAssociatedEntityPersister( factory ).getIdentifierType();
} }
protected EntityPersister getAssociatedEntityPersister(final SessionFactoryImplementor factory) { public EntityPersister getAssociatedEntityPersister(final SessionFactoryImplementor factory) {
final EntityPersister persister = associatedEntityPersister; final EntityPersister persister = associatedEntityPersister;
//The following branch implements a simple lazy-initialization, but rather than the canonical //The following branch implements a simple lazy-initialization, but rather than the canonical
//form it returns the local variable to avoid a second volatile read: associatedEntityPersister //form it returns the local variable to avoid a second volatile read: associatedEntityPersister
@ -503,7 +503,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
} }
protected final Object getIdentifier(Object value, SharedSessionContractImplementor session) throws HibernateException { protected final Object getIdentifier(Object value, SharedSessionContractImplementor session) throws HibernateException {
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { if ( isReferenceToIdentifierProperty() ) {
return ForeignKeys.getEntityIdentifierIfNotUnsaved( return ForeignKeys.getEntityIdentifierIfNotUnsaved(
getAssociatedEntityName(), getAssociatedEntityName(),
value, value,
@ -639,7 +639,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
* or unique key property name. * or unique key property name.
*/ */
public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException { public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException {
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { if ( isReferenceToIdentifierProperty() ) {
return getIdentifierType( factory ); return getIdentifierType( factory );
} }
else { else {
@ -663,12 +663,14 @@ public abstract class EntityType extends AbstractType implements AssociationType
*/ */
public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory) public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
throws MappingException { throws MappingException {
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { return isReferenceToIdentifierProperty()
return factory.getIdentifierPropertyName( getAssociatedEntityName() ); ? factory.getIdentifierPropertyName( getAssociatedEntityName() )
} : uniqueKeyPropertyName;
else { }
return uniqueKeyPropertyName;
} public boolean isReferenceToIdentifierProperty() {
return isReferenceToPrimaryKey()
|| uniqueKeyPropertyName == null;
} }
/** /**