Skip to content

Commit e5ed82c

Browse files
committed
expose two operations on EntityType for use by Hibernate Reactive
see hibernate/hibernate-reactive#954
1 parent 3edad14 commit e5ed82c

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

hibernate-core/src/main/java/org/hibernate/type/EntityType.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ public Type getSemiResolvedType(SessionFactoryImplementor factory) {
488488
return getAssociatedEntityPersister( factory ).getIdentifierType();
489489
}
490490

491-
protected EntityPersister getAssociatedEntityPersister(final SessionFactoryImplementor factory) {
491+
public EntityPersister getAssociatedEntityPersister(final SessionFactoryImplementor factory) {
492492
final EntityPersister persister = associatedEntityPersister;
493493
//The following branch implements a simple lazy-initialization, but rather than the canonical
494494
//form it returns the local variable to avoid a second volatile read: associatedEntityPersister
@@ -503,7 +503,7 @@ protected EntityPersister getAssociatedEntityPersister(final SessionFactoryImple
503503
}
504504

505505
protected final Object getIdentifier(Object value, SharedSessionContractImplementor session) throws HibernateException {
506-
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
506+
if ( isReferenceToIdentifierProperty() ) {
507507
return ForeignKeys.getEntityIdentifierIfNotUnsaved(
508508
getAssociatedEntityName(),
509509
value,
@@ -639,7 +639,7 @@ Type getIdentifierType(final SharedSessionContractImplementor session) {
639639
* or unique key property name.
640640
*/
641641
public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException {
642-
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
642+
if ( isReferenceToIdentifierProperty() ) {
643643
return getIdentifierType( factory );
644644
}
645645
else {
@@ -663,12 +663,14 @@ public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingEx
663663
*/
664664
public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
665665
throws MappingException {
666-
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
667-
return factory.getIdentifierPropertyName( getAssociatedEntityName() );
668-
}
669-
else {
670-
return uniqueKeyPropertyName;
671-
}
666+
return isReferenceToIdentifierProperty()
667+
? factory.getIdentifierPropertyName( getAssociatedEntityName() )
668+
: uniqueKeyPropertyName;
669+
}
670+
671+
public boolean isReferenceToIdentifierProperty() {
672+
return isReferenceToPrimaryKey()
673+
|| uniqueKeyPropertyName == null;
672674
}
673675

674676
/**

0 commit comments

Comments
 (0)