HHH-11928 : Empty left join fetched collection is uninitialized when collection key is composite with hibernate.create_empty_composites.enabled=true

This commit is contained in:
Gail Badner 2017-08-15 22:17:56 -07:00
parent 310a43e5e7
commit 65c6964c96
1 changed files with 10 additions and 1 deletions

View File

@ -870,7 +870,16 @@ public abstract class AbstractCollectionPersister
@Override
public Object readKey(ResultSet rs, String[] aliases, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
return getKeyType().nullSafeGet( rs, aliases, session, null );
// First hydrate the collection key to check if it is null.
// Don't bother resolving the collection key if the hydrated value is null.
// Implementation note: if collection key is a composite value, then resolving a null value will
// result in instantiating an empty composite if AvailableSettings#CREATE_EMPTY_COMPOSITES_ENABLED
// is true. By not resolving a null value for a composite key, we avoid the overhead of instantiating
// an empty composite, checking if it is equivalent to null (it should be), then ultimately throwing
// out the empty value.
final Object hydratedKey = getKeyType().hydrate( rs, aliases, session, null );
return hydratedKey == null ? null : getKeyType().resolve( hydratedKey, session, null );
}
/**