Skip to content
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

Count query removes distinct phrase if from part of JPA query contains newline character #2341

Closed
kaliberr44 opened this issue Oct 19, 2021 · 2 comments
Labels
in: query-parser Everything related to parsing JPQL or SQL type: bug A general bug

Comments

@kaliberr44
Copy link

It seems that there is newline character after the entity alias name in FROM part of the query before the JOIN the distinct is removed from the count.

Incorrect behavior:

@Query("""
    SELECT DISTINCT entity1
    FROM Entity1 entity1 
    LEFT JOIN Entity2 entity2 ON entity1.key = entity2.key""")

returns

select count(entity1) FROM Entity1 entity1
LEFT JOIN Entity2 entity2 ON entity1.key = entity2.key

Correct behaviour:

@Query("""
    SELECT DISTINCT entity1
    FROM Entity1 entity1 LEFT JOIN Entity2 entity2 ON entity1.key = entity2.key""")

returns

select count(DISTINCT entity1) FROM Entity1 entity1 LEFT JOIN Entity2 entity2 ON entity1.key = entity2.key

From testing if the FROM and JOIN are in the same line, and WHERE is new line then this incorrect behavior also occurs.

For now I have solved it with countProjection = "distinct entity1".

@kaliberr44
Copy link
Author

This might also be the case in #2177

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 19, 2021
@schauder schauder added in: query-parser Everything related to parsing JPQL or SQL type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 19, 2021
DiegoKrupitza added a commit to DiegoKrupitza/spring-data-jpa that referenced this issue Dec 17, 2021
The `COUNT_MATCH` did not consider line breaks after the `from` clause or the `where` clause. This lead to a no match scenario in the construction of the count query. With the fix we now consider line breaks/whitespaces after the `from` and `where` clause.

Closes spring-projects#2341
Related tickets spring-projects#2177
gregturn pushed a commit that referenced this issue Mar 28, 2022
The `COUNT_MATCH` does not consider line breaks after the `from` clause or the `where` clause. This leads to a no match scenario in the construction of the count query. With the fix we now consider line breaks/whitespaces after the `from` and `where` clause.

See #2341
Related tickets: #2177
gregturn pushed a commit that referenced this issue Mar 28, 2022
The `COUNT_MATCH` does not consider line breaks after the `from` clause or the `where` clause. This leads to a no match scenario in the construction of the count query. With the fix we now consider line breaks/whitespaces after the `from` and `where` clause.

See #2341
Related tickets: #2177
gregturn pushed a commit that referenced this issue Mar 28, 2022
The `COUNT_MATCH` does not consider line breaks after the `from` clause or the `where` clause. This leads to a no match scenario in the construction of the count query. With the fix we now consider line breaks/whitespaces after the `from` and `where` clause.

See #2341
Related tickets: #2177
gregturn pushed a commit that referenced this issue Mar 28, 2022
The `COUNT_MATCH` does not consider line breaks after the `from` clause or the `where` clause. This leads to a no match scenario in the construction of the count query. With the fix we now consider line breaks/whitespaces after the `from` and `where` clause.

See #2341
Related tickets: #2177
@gregturn gregturn added this to the 3.0 M4 (2022.0.0) milestone Mar 28, 2022
@ruslanys
Copy link

Please have a look #2177 (comment)

gregturn pushed a commit that referenced this issue May 4, 2022
In commit 3e64d9a a bug got introduced that uses the next symbol after the table name for the count function. With this commit this should be now resolved. The count query will use `*` when there is no alias present nor a variable.

Related tickets #2341, #2177, #2260, #2511
gregturn pushed a commit that referenced this issue May 4, 2022
In commit 3e64d9a a bug got introduced that uses the next symbol after the table name for the count function. With this commit this should be now resolved. The count query will use `*` when there is no alias present nor a variable.

Related tickets #2341, #2177, #2260, #2511
gregturn pushed a commit that referenced this issue May 4, 2022
In commit 3e64d9a a bug got introduced that uses the next symbol after the table name for the count function. With this commit this should be now resolved. The count query will use `*` when there is no alias present nor a variable.

Related tickets #2341, #2177, #2260, #2511
gregturn pushed a commit that referenced this issue May 4, 2022
In commit 3e64d9a a bug got introduced that uses the next symbol after the table name for the count function. With this commit this should be now resolved. The count query will use `*` when there is no alias present nor a variable.

Related tickets #2341, #2177, #2260, #2511
This issue was closed.
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 type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants