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

Spring Data JPA generates incorrect JPQL query for sorted pagination request with UNION clause #3427

Closed
Pedroloma opened this issue Apr 15, 2024 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@Pedroloma
Copy link

Pedroloma commented Apr 15, 2024

After updating my app from 3.0.8 to 3.1.10, I get an exception for a JPL with UNION clauses, when the query is pageable and sorted.

I've created a GitHub repo where you can reproduce the issue: https://github.com/Pedroloma/JpaWithUnionAndPageableAndSortedApplication

I think, that this issue could be related to this other one: #2969

This is the exception thrown and its stack trace:

Caused by: org.hibernate.query.sqm.ParsingException: line 1:79 mismatched input 'ascUNION' expecting {<EOF>, ',', '.', '[', '+', '-', '*', '/', '%', '||', ASC, BY, DAY, DESC, EPOCH, FETCH, HOUR, LIMIT, MINUTE, MONTH, NANOSECOND, NULLS, OFFSET, QUARTER, SECOND, WEEK, YEAR}
	at org.hibernate.query.hql.internal.StandardHqlTranslator$1.syntaxError(StandardHqlTranslator.java:46)
	at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41)
	at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:543)
	at org.antlr.v4.runtime.DefaultErrorStrategy.reportInputMismatch(DefaultErrorStrategy.java:327)
	at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:139)
	at org.hibernate.grammars.hql.HqlParser.statement(HqlParser.java:361)
	at org.hibernate.query.hql.internal.StandardHqlTranslator.parseHql(StandardHqlTranslator.java:127)
	at org.hibernate.query.hql.internal.StandardHqlTranslator.translate(StandardHqlTranslator.java:77)
	at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.createHqlInterpretation(QueryInterpretationCacheStandardImpl.java:165)
	at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.resolveHqlInterpretation(QueryInterpretationCacheStandardImpl.java:147)
	at org.hibernate.internal.AbstractSharedSessionContract.interpretHql(AbstractSharedSessionContract.java:741)
	at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:786)
	... 212 common frames omitted

Please, let me know if you guys need some extra information.

Thanks in advance.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 15, 2024
@christophstrobl christophstrobl self-assigned this Apr 16, 2024
@christophstrobl
Copy link
Member

@Pedroloma thanks for reporting, we'll look into this.

@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 16, 2024
@mp911de mp911de added this to the 3.4 M1 (2024.1.0) milestone Aug 2, 2024
@mp911de mp911de closed this as completed in b02081b Aug 2, 2024
mp911de added a commit that referenced this issue Aug 2, 2024
Ensure ordering of the last query only, applying ordering after the set operation.

Original pull request: #3429
See #3427
@Pedroloma
Copy link
Author

Pedroloma commented Sep 27, 2024

Thank you for resolving this issue, @christophstrobl .
We are currently developing a new product using Spring Boot 3.1.10, and we need to release the final version in four weeks. Upgrading to a major release like 3.4.x may not be feasible within our timeline. Would it be possible to backport this fix to a production-ready release such as 3.2.x or 3.3.x?
We appreciate your consideration!

@mp911de
Copy link
Member

mp911de commented Oct 1, 2024

Thanks for reaching out. I created #3630 to backport the fix into 3.2 and 3.3 development lines.

mp911de pushed a commit that referenced this issue Oct 1, 2024
Make sure to append space after order by clause and fix alias detection for wrapped sub select.
Also make sure to ignore alias used in subselect so they do not conflict with root ones.

Render order by only on full select if set operator is present in EQL.

Closes #3630
Original pull request: #3429
See #3427
mp911de pushed a commit that referenced this issue Oct 1, 2024
Make sure to append space after order by clause and fix alias detection for wrapped sub select.
Also make sure to ignore alias used in subselect so they do not conflict with root ones.

Render order by only on full select if set operator is present in EQL.

Closes #3630
Original pull request: #3429
See #3427
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants