HHH-8704 - ManyToOneType#scheduleBatchLoadIfNeeded creates EntityKey instances even if absolutely not necessary

This commit is contained in:
Steve Ebersole 2013-11-16 14:07:35 -06:00
parent 449c558365
commit 7f82763843
1 changed files with 6 additions and 4 deletions

View File

@ -187,7 +187,7 @@ public class ManyToOneType extends EntityType {
// return the (fully resolved) identifier value, but do not resolve // return the (fully resolved) identifier value, but do not resolve
// to the actual referenced entity instance // to the actual referenced entity instance
// NOTE: the owner of the association is not really the owner of the id! // 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 ); .nullSafeGet( rs, names, session, null );
scheduleBatchLoadIfNeeded( id, session ); scheduleBatchLoadIfNeeded( id, session );
return id; return id;
@ -201,9 +201,11 @@ public class ManyToOneType extends EntityType {
//cannot batch fetch by unique key (property-ref associations) //cannot batch fetch by unique key (property-ref associations)
if ( uniqueKeyPropertyName == null && id != null ) { if ( uniqueKeyPropertyName == null && id != null ) {
final EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() ); final EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() );
final EntityKey entityKey = session.generateEntityKey( id, persister ); if ( persister.isBatchLoadable() ) {
if ( entityKey.isBatchLoadable() && !session.getPersistenceContext().containsEntity( entityKey ) ) { final EntityKey entityKey = session.generateEntityKey( id, persister );
session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey ); if ( !session.getPersistenceContext().containsEntity( entityKey ) ) {
session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey );
}
} }
} }
} }