Skip to content

Count query is created incorrectly when selecting new objects [DATAJPA-1587] #1895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Aug 8, 2019 · 1 comment
Assignees
Labels
in: query-parser Everything related to parsing JPQL or SQL status: duplicate A duplicate of another issue type: bug A general bug

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Aug 8, 2019

Jeroen Hendrickx opened DATAJPA-1587 and commented

When I create a query that selects a new Object using a Pageable, the generated count query is incorrect.

E.g. the following query:

@Query("SELECT new com.acme.Foo(fooBar) " +
"FROM FooBar fooBar")

Generated the following count query:

select count(new com.acme.Foo(fooBar)) FROM FooBar fooBar

In release 2.1.9 the generated query was

select count(fooBar) FROM FooBar fooBar

which is the correct query.

It looks like this is a side effect from the changes requested in DATAJPA-1564.

Note, if I change the query and start it with a space, the count query is generated properly.
i've managed to write some tests on this in the org.springframework.data.jpa.repository.query.QueryTest:

This test passes:

@Test
public void createCountQueryForSelectNewStartingWithSpace() throws Exception {
        assertCountQuery(" SELECT new com.acme.Foo(fooBar) FROM FooBar fooBar", " select count(fooBar) FROM FooBar fooBar");
    }

While this test fails:

@Test
public void createCountQueryForSelectNewNotStartingWithSpace() throws Exception {
        assertCountQuery("SELECT new com.acme.Foo(fooBar) FROM FooBar fooBar", "select count(fooBar) FROM FooBar fooBar");
    }

Affects: 2.1.10 (Lovelace SR10)

Issue Links:

  • DATAJPA-1732 Spring jpql query validation failed for constructor method on spring boot 2.3
    ("is duplicated by")

1 votes, 1 watchers

@gregturn
Copy link
Contributor

Duplicates #1869.

Resolved via f2e7bdd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: query-parser Everything related to parsing JPQL or SQL status: duplicate A duplicate of another issue type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants