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

BadJpqlGrammarException: Line 1:236 token recognition error at: '!'; #2970

Closed
sergey-morenets opened this issue May 23, 2023 · 7 comments
Closed
Assignees
Labels
in: query-parser Everything related to parsing JPQL or SQL type: regression A regression from a previous release

Comments

@sergey-morenets
Copy link

Hi

We tried to upgrade our Spring Boot project and used Spring Data JPA 3.1 (previously we had 3.0.x).
And we received a lot of errors in our JPQL (@query) queries, for example, if we used "!=" operator then we received the following exception trying to execute this query:

Caused by: org.springframework.data.jpa.repository.query.BadJpqlGrammarException: Line 1:236 token recognition error at: '!'; Bad JPQL grammar.

We are aware that JPA officially supports "<>" operator but "!=" also worked before 3.1.
We understood that this issue is caused by new HQL parser in Spring Data JPA however we couldn't find any information about these breaking changes in WIKI: https://github.com/spring-projects/spring-data-commons/wiki/Spring-Data-2023.0-%28Ullman%29-Release-Notes

So what we suggest:

  1. Add information about breaking changes in WIKI/documentation
  2. Currently this error happens during query execution. But if query is invalid then this error should be fired on application startup (like any other query validation errors).
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 23, 2023
@gregturn
Copy link
Contributor

gregturn commented May 23, 2023

The query parser was meant to seamlessly be swapped into place for Hibernate (HQL) and pure JPA (JPQL). There are no official attempts to "alter" the format of queries.

Can you post the precise query so we can build a reproducing test case and properly handle it?

@gregturn gregturn self-assigned this May 23, 2023
@gregturn gregturn 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 May 23, 2023
@gregturn
Copy link
Contributor

I can also confirm that Hibernate's own query parser has:

NOT_EQUAL : '!=' | '^=' | '<>';

@sergey-morenets
Copy link
Author

The query parser was meant to seamlessly be swapped into place for Hibernate (HQL) and pure JPA (JPQL). There are no official attempts to "alter" the format of queries.

Can you post the precise query so we can build a reproducing test case and properly handle it?

Hi @gregturn

Thank you for the quick response. You can take any query with "!=", for example,

SELECT u FROM User u WHERE u.id != 1

@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 May 23, 2023
@gregturn
Copy link
Contributor

Heh, it's even written plain as day...and I missed it.

Screenshot 2023-05-23 at 8 04 24 AM

gregturn added a commit that referenced this issue May 23, 2023
Hibernate also supports "!=" and "^=" as NOT EQUALS operators.

See #2970
@gregturn gregturn added type: regression A regression from a previous release in: query-parser Everything related to parsing JPQL or SQL and removed status: feedback-provided Feedback has been provided labels May 23, 2023
@gregturn gregturn added this to the 3.2 M1 (2023.1.0) milestone May 23, 2023
@gregturn gregturn linked a pull request May 23, 2023 that will close this issue
gregturn added a commit that referenced this issue May 23, 2023
Hibernate also supports "!=" and "^=" as NOT EQUALS operators.

See #2970
Original Pull Request #2972
gregturn added a commit that referenced this issue May 23, 2023
Hibernate also supports "!=" and "^=" as NOT EQUALS operators.

See #2970
Original Pull Request #2972
@gregturn
Copy link
Contributor

Merged to main and backported to 3.1.x.

@gpolet
Copy link

gpolet commented Jul 7, 2023

Merged to main and backported to 3.1.x.

Looks like this one didn't make into 3.1.1

@gregturn
Copy link
Contributor

Actually, it's right here:

https://github.com/spring-projects/spring-data-jpa/blob/3.1.x/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Hql.g4#L592

We actually have a parser for HQL (which this ticket addressed) as well as standard JPQL.

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: regression A regression from a previous release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants