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 derivation from DISTINCT queries seems to be broken #3269

Closed
da-z opened this issue Dec 15, 2023 · 9 comments
Closed

Count query derivation from DISTINCT queries seems to be broken #3269

da-z opened this issue Dec 15, 2023 · 9 comments
Assignees
Labels
type: regression A regression from a previous release

Comments

@da-z
Copy link

da-z commented Dec 15, 2023

I have a large chunk of JPA code that was working fine in Spring Boot 2.x but not in Spring Boot 3.x (Hibernate 6 on Oracle and H2 in Oracle mode in tests):

Sample JPQL query:

SELECT DISTINCT abc AS x FROM T -- (note the AS alias)

In SB 3.x I am getting the error: At 1:n and token 'AS', no viable alternative at input 'SELECT count(DISTINCT abc *AS x

And indeed, that's not a valid SQL query because aliases are not allowed in that scenario.

My take on this is: either strip the alias, or derive the Count query like this, which means you don't need to mess with the original query:

SELECT COUNT(*) FROM ({original_sql}) -- I assume this is how it is working in SB 2.x
@da-z da-z changed the title Count derivation from DISTINCT queries is broken Count query derivation from DISTINCT queries seems to be broken Dec 15, 2023
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 15, 2023
@christophstrobl
Copy link
Member

Thanks for reporting, sounds like you already have a test that you could share to help us diagnose the issue. Would you mind taking the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem?

@christophstrobl christophstrobl added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 15, 2023
@christophstrobl christophstrobl self-assigned this Dec 15, 2023
@da-z
Copy link
Author

da-z commented Dec 15, 2023

Sure: https://github.com/da-z/spring-data-jpa-issue-3269 (just run the test)

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 15, 2023
@gtiburcio
Copy link

I'm having the same problem here.

@christophstrobl
Copy link
Member

We're working on a solution. Early snapshots (branch builds) should be available soon.

@christophstrobl christophstrobl added type: regression A regression from a previous release and removed status: feedback-provided Feedback has been provided labels Dec 18, 2023
@da-z
Copy link
Author

da-z commented Mar 8, 2024

Hello. Will this fix be merged into main?

@THD-Thomas-Lang
Copy link

I have the same problem and i could it solve by using a dedicated countQuery() in addition to your @Query(). So kind of this way:@Query("SELECT DISTINCT abc AS x FROM T", countQuery="select count(*) FROM T")

@da-z
Copy link
Author

da-z commented Apr 9, 2024

@THD-Thomas-Lang The regression has already been fixed. All we need is more upvoters for this PR to be merged: #3276

@THD-Thomas-Lang
Copy link

Didn´t know that there is an upvote function? Thank you!

@da-z
Copy link
Author

da-z commented Apr 9, 2024

There is no upvote function but you can leave a comment or react to one of the existing comments. Thanks!

mp911de pushed a commit that referenced this issue Apr 11, 2024
mp911de added a commit that referenced this issue Apr 11, 2024
Apply select list rewriting to EQL and JPQL parsers as well.

See: #3269
Original pull request: #3276
mp911de pushed a commit that referenced this issue Apr 11, 2024
mp911de added a commit that referenced this issue Apr 11, 2024
Apply select list rewriting to EQL and JPQL parsers as well.

See: #3269
Original pull request: #3276
mp911de added a commit that referenced this issue Apr 11, 2024
Apply select list rewriting to EQL and JPQL parsers as well.

See: #3269
Original pull request: #3276
@mp911de mp911de added this to the 3.1.11 (2023.0.11) milestone Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants