Skip to content

Commit 28de271

Browse files
committed
Verify that projections work with subqueries.
Interface-based projections used to NOT work when the query had a subquery in it. But with the new query parser, it already handles it. So this simply captures the test providing that corner case. See #2008 Original Pull Request: #420
1 parent 97255cf commit 28de271

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryFinderTests.java

+11
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,15 @@ void rejectsStreamExecutionIfNoSurroundingTransactionActive() {
315315
void executesNamedQueryWithConstructorExpression() {
316316
userRepository.findByNamedQueryWithConstructorExpression();
317317
}
318+
319+
@Test // DATAJPA-1713, GH-2008
320+
public void selectProjectionWithSubselect() {
321+
322+
List<UserRepository.NameOnly> dtos = userRepository.findProjectionBySubselect();
323+
324+
assertThat(dtos).flatExtracting(UserRepository.NameOnly::getFirstname) //
325+
.containsExactly("Dave", "Carter", "Oliver August");
326+
assertThat(dtos).flatExtracting(UserRepository.NameOnly::getLastname) //
327+
.containsExactly("Matthews", "Beauford", "Matthews");
328+
}
318329
}

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java

+4
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,10 @@ List<String> findAllAndSortByFunctionResultNamedParameter(@Param("namedParameter
718718
nativeQuery = true)
719719
int mergeNativeStatement();
720720

721+
// DATAJPA-1713, GH-2008
722+
@Query("select u from User u where u.firstname >= (select Min(u0.firstname) from User u0)")
723+
List<NameOnly> findProjectionBySubselect();
724+
721725
interface RolesAndFirstname {
722726

723727
String getFirstname();

0 commit comments

Comments
 (0)