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
This commit is contained in:
Greg L. Turnquist
2023-05-31 15:52:16 -05:00
parent 97255cfabb
commit 28de27107d
2 changed files with 15 additions and 0 deletions

View File

@@ -315,4 +315,15 @@ class UserRepositoryFinderTests {
void executesNamedQueryWithConstructorExpression() {
userRepository.findByNamedQueryWithConstructorExpression();
}
@Test // DATAJPA-1713, GH-2008
public void selectProjectionWithSubselect() {
List<UserRepository.NameOnly> dtos = userRepository.findProjectionBySubselect();
assertThat(dtos).flatExtracting(UserRepository.NameOnly::getFirstname) //
.containsExactly("Dave", "Carter", "Oliver August");
assertThat(dtos).flatExtracting(UserRepository.NameOnly::getLastname) //
.containsExactly("Matthews", "Beauford", "Matthews");
}
}

View File

@@ -718,6 +718,10 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
nativeQuery = true)
int mergeNativeStatement();
// DATAJPA-1713, GH-2008
@Query("select u from User u where u.firstname >= (select Min(u0.firstname) from User u0)")
List<NameOnly> findProjectionBySubselect();
interface RolesAndFirstname {
String getFirstname();