diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/BatchFetchQueueHelper.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/BatchFetchQueueHelper.java index c54387a09d..5d04bbaaa9 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/BatchFetchQueueHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/BatchFetchQueueHelper.java @@ -55,8 +55,8 @@ public class BatchFetchQueueHelper { LOG.debug( "Not all entities were loaded." ); Set idSet = new HashSet<>( Arrays.asList( ids ) ); for ( Object result : results ) { - final Serializable id = session.getPersistenceContext().getEntry( result ).getId(); - idSet.remove( id ); + // All results should be in the PersistenceContext + idSet.remove( session.getContextEntityIdentifier( result ) ); } assert idSet.size() == ids.length - results.size(); if ( LOG.isDebugEnabled() ) {