From 531e5d428a30122a65d80101f12956b6c4e48a2e Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Sat, 16 Nov 2013 14:07:35 -0600 Subject: [PATCH] HHH-8704 - ManyToOneType#scheduleBatchLoadIfNeeded creates EntityKey instances even if absolutely not necessary (cherry picked from commit 7f82763843aa0d2fab4f086b7d08b4622fc65728) --- .../main/java/org/hibernate/type/ManyToOneType.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 7fb9c8fe78..63c76af840 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java @@ -187,7 +187,7 @@ public class ManyToOneType extends EntityType { // return the (fully resolved) identifier value, but do not resolve // to the actual referenced entity instance // NOTE: the owner of the association is not really the owner of the id! - Serializable id = (Serializable) getIdentifierOrUniqueKeyType( session.getFactory() ) + final Serializable id = (Serializable) getIdentifierOrUniqueKeyType( session.getFactory() ) .nullSafeGet( rs, names, session, null ); scheduleBatchLoadIfNeeded( id, session ); return id; @@ -201,9 +201,11 @@ public class ManyToOneType extends EntityType { //cannot batch fetch by unique key (property-ref associations) if ( uniqueKeyPropertyName == null && id != null ) { final EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() ); - final EntityKey entityKey = session.generateEntityKey( id, persister ); - if ( entityKey.isBatchLoadable() && !session.getPersistenceContext().containsEntity( entityKey ) ) { - session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey ); + if ( persister.isBatchLoadable() ) { + final EntityKey entityKey = session.generateEntityKey( id, persister ); + if ( !session.getPersistenceContext().containsEntity( entityKey ) ) { + session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey ); + } } } }