Repository navigation
Description
HqlParser cannot parse the valid HQL query. Here is the query
SELECT COUNT(f)
FROM FooEntity f
WHERE f.name IN ('Y', 'Basic', 'Remit')
AND f.size = 10
HAVING COUNT(f) > 0
Here is the example https://github.com/afrunt/eql-bug-check
(there are separate profiles for HQL and EQL
mvn clean package -U -P hql
mvn clean package -U -P eql
)
I will add similar upcoming issues to this project if any
NOTE: EqlParser works fine with this case
Caused by: org.springframework.data.jpa.repository.query.BadJpqlGrammarException: At 5:0 and token 'HAVING', mismatched input 'HAVING', expecting one of the following tokens: , ',', '/', '||', '*', AND, BY, DAY, EPOCH, EXCEPT, GROUP, HOUR, INTERSECT, MINUTE, MONTH, NANOSECOND, OR, ORDER, QUARTER, SECOND, UNION, WEEK, YEAR, '+', '-'; Bad HQL grammar [SELECT COUNT(f)
FROM FooEntity f
WHERE f.name IN ('Y', 'Basic', 'Remit')
AND f.size = 10
HAVING COUNT(f) > 0
]
at org.springframework.data.jpa.repository.query.BadJpqlGrammarErrorListener.syntaxError(BadJpqlGrammarErrorListener.java:53) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41) ~[antlr4-runtime-4.13.0.jar:4.13.0]
at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:544) ~[antlr4-runtime-4.13.0.jar:4.13.0]
at org.antlr.v4.runtime.DefaultErrorStrategy.reportInputMismatch(DefaultErrorStrategy.java:327) ~[antlr4-runtime-4.13.0.jar:4.13.0]
at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:139) ~[antlr4-runtime-4.13.0.jar:4.13.0]
at org.springframework.data.jpa.repository.query.HqlParser.start(HqlParser.java:346) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.JpaQueryEnhancer.parse(JpaQueryEnhancer.java:101) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.JpaQueryEnhancer$HqlQueryParser.(JpaQueryEnhancer.java:288) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.JpaQueryEnhancer$HqlQueryParser.parseQuery(JpaQueryEnhancer.java:300) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.JpaQueryEnhancer.forHql(JpaQueryEnhancer.java:163) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.QueryEnhancerFactory.forQuery(QueryEnhancerFactory.java:68) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.StringQuery.(StringQuery.java:98) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.StringQuery.(StringQuery.java:77) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.ExpressionBasedStringQuery.(ExpressionBasedStringQuery.java:65) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.(AbstractStringBasedJpaQuery.java:84) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.(SimpleJpaQuery.java:65) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:49) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:174) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:254) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:99) ~[spring-data-jpa-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:116) ~[spring-data-commons-3.4.5-SNAPSHOT.jar:3.4.5-SNAPSHOT]
... 110 common frames omitted
Activity
[-]HQL parser rejects HAVING without GROUP BY[/-][+]EQL parser rejects HAVING without GROUP BY[/+][-]EQL parser rejects HAVING without GROUP BY[/-][+]HQL parser rejects HAVING without GROUP BY[/+]afrunt commentedon Apr 14, 2025
@mp911de this time it is related to HQL, not EQL
mp911de commentedon Apr 14, 2025
All right, thanks for clarifying. I noticed the same reproducer repository and assumed a typo.
afrunt commentedon Apr 14, 2025
@mp911de I reworked the project and added two maven profiles to be able to check Hql and Eql for the same queries
mp911de commentedon Apr 14, 2025
FWIW, for those parser pure-syntax issues it should be fine to just have the offending query text, you don't need to craft new tests (maybe once we encounter some issue that terminates with a Hibernate stack trace).
afrunt commentedon Apr 14, 2025
@mp911de sure, it is more for myself. For better understanding. Also to make sure, that I'm reporting a real reproducible bug
mp911de commentedon Apr 14, 2025
HAVING COUNT(f) > 0withoutGROUP BYis invalid HQL (testing against the Hibernate parser). In any case, the JPA spec allows absence ofGROPUP BYso we should enable it.afrunt commentedon Apr 14, 2025
@mp911de now I see. I didn't read the stacktrace precisely and missed the fact, that exception comes from Hibernate, when I'm trying to execute the query
Allow HQL HAVING without enforcing GROUP BY.
Allow HQL HAVING without enforcing GROUP BY.
Allow HQL HAVING without enforcing GROUP BY.
mp911de commentedon Apr 14, 2025
That's fixed now.
afrunt commentedon Apr 14, 2025
@mp911de incredible, thank you
Allow HQL HAVING without enforcing GROUP BY.