From cc34823cbe5eee7100134d1c3948ff9ee9f819ca Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Tue, 11 Jul 2023 10:32:14 -0500 Subject: [PATCH] Handle != as NOT EQUALS for JPQL. See #3061. --- .../data/jpa/repository/query/Jpql.g4 | 17 ++++++++++------- .../query/JpqlQueryRendererTests.java | 5 +++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4 b/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4 index 13d6a24a79..e17a919f4a 100644 --- a/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4 +++ b/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4 @@ -164,7 +164,7 @@ update_clause ; update_item - : (identification_variable '.')? (single_valued_embeddable_object_field '.')* (state_field | single_valued_object_field) '=' new_value + : (identification_variable '.')? (single_valued_embeddable_object_field '.')* (state_field | single_valued_object_field) EQUAL new_value ; new_value @@ -377,21 +377,21 @@ all_or_any_expression comparison_expression : string_expression comparison_operator (string_expression | all_or_any_expression) - | boolean_expression op=('=' | '<>') (boolean_expression | all_or_any_expression) - | enum_expression op=('=' | '<>') (enum_expression | all_or_any_expression) + | boolean_expression op=(EQUAL | NOT_EQUAL) (boolean_expression | all_or_any_expression) + | enum_expression op=(EQUAL | NOT_EQUAL) (enum_expression | all_or_any_expression) | datetime_expression comparison_operator (datetime_expression | all_or_any_expression) - | entity_expression op=('=' | '<>') (entity_expression | all_or_any_expression) + | entity_expression op=(EQUAL | NOT_EQUAL) (entity_expression | all_or_any_expression) | arithmetic_expression comparison_operator (arithmetic_expression | all_or_any_expression) - | entity_type_expression op=('=' | '<>') entity_type_expression + | entity_type_expression op=(EQUAL | NOT_EQUAL) entity_type_expression ; comparison_operator - : op='=' + : op=EQUAL | op='>' | op='>=' | op='<' | op='<=' - | op='<>' + | op=NOT_EQUAL ; arithmetic_expression @@ -841,6 +841,9 @@ VALUE : V A L U E; WHEN : W H E N; WHERE : W H E R E; +EQUAL : '=' ; +NOT_EQUAL : '<>' | '!=' ; + CHARACTER : '\'' (~ ('\'' | '\\')) '\'' ; IDENTIFICATION_VARIABLE : ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '$' | '_') ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '0' .. '9' | '$' | '_')* ; diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java index f736c635be..368b1379ab 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java @@ -948,4 +948,9 @@ void typeShouldBeAValidParameter() { assertQuery("select e from Employee e where e.type = :_type"); assertQuery("select te from TestEntity te where te.type = :type"); } + + @Test // GH-3061 + void alternateNotEqualsOperatorShouldWork() { + assertQuery("select e from Employee e where e.firstName != :name"); + } }