diff --git a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java index 503810fba..71335e842 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java @@ -633,6 +633,9 @@ public abstract class QueryUtils { return false; } + // if this path is part of the select list we need to generate an explicit outer join in order to prevent Hibernate + // to use an inner join instead. + // see https://hibernate.atlassian.net/browse/HHH-12999. if (isLeafProperty && !isForSelection && !attribute.isCollection()) { return false; } diff --git a/src/test/java/org/springframework/data/jpa/repository/projections/ProjectionJoinIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/projections/ProjectionJoinIntegrationTests.java index 2146cbd5a..08bdec3c8 100644 --- a/src/test/java/org/springframework/data/jpa/repository/projections/ProjectionJoinIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/projections/ProjectionJoinIntegrationTests.java @@ -47,7 +47,7 @@ public class ProjectionJoinIntegrationTests { @Autowired private UserRepository userRepository; - @Test + @Test // DATAJPA-1418 public void findByIdPerformsAnOuterJoin() { User user = userRepository.save(new User());