Skip to content

Commit d1043ef

Browse files
committed
Handle != as NOT EQUALS for JPQL.
See #3061.
1 parent ab34ee6 commit d1043ef

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4

+10-7
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ update_clause
164164
;
165165

166166
update_item
167-
: (identification_variable '.')? (single_valued_embeddable_object_field '.')* (state_field | single_valued_object_field) '=' new_value
167+
: (identification_variable '.')? (single_valued_embeddable_object_field '.')* (state_field | single_valued_object_field) EQUAL new_value
168168
;
169169

170170
new_value
@@ -377,21 +377,21 @@ all_or_any_expression
377377

378378
comparison_expression
379379
: string_expression comparison_operator (string_expression | all_or_any_expression)
380-
| boolean_expression op=('=' | '<>') (boolean_expression | all_or_any_expression)
381-
| enum_expression op=('=' | '<>') (enum_expression | all_or_any_expression)
380+
| boolean_expression op=(EQUAL | NOT_EQUAL) (boolean_expression | all_or_any_expression)
381+
| enum_expression op=(EQUAL | NOT_EQUAL) (enum_expression | all_or_any_expression)
382382
| datetime_expression comparison_operator (datetime_expression | all_or_any_expression)
383-
| entity_expression op=('=' | '<>') (entity_expression | all_or_any_expression)
383+
| entity_expression op=(EQUAL | NOT_EQUAL) (entity_expression | all_or_any_expression)
384384
| arithmetic_expression comparison_operator (arithmetic_expression | all_or_any_expression)
385-
| entity_type_expression op=('=' | '<>') entity_type_expression
385+
| entity_type_expression op=(EQUAL | NOT_EQUAL) entity_type_expression
386386
;
387387

388388
comparison_operator
389-
: op='='
389+
: op=EQUAL
390390
| op='>'
391391
| op='>='
392392
| op='<'
393393
| op='<='
394-
| op='<>'
394+
| op=NOT_EQUAL
395395
;
396396

397397
arithmetic_expression
@@ -841,6 +841,9 @@ VALUE : V A L U E;
841841
WHEN : W H E N;
842842
WHERE : W H E R E;
843843

844+
EQUAL : '=' ;
845+
NOT_EQUAL : '<>' | '!=' ;
846+
844847

845848
CHARACTER : '\'' (~ ('\'' | '\\')) '\'' ;
846849
IDENTIFICATION_VARIABLE : ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '$' | '_') ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '0' .. '9' | '$' | '_')* ;

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java

+5
Original file line numberDiff line numberDiff line change
@@ -948,4 +948,9 @@ void typeShouldBeAValidParameter() {
948948
assertQuery("select e from Employee e where e.type = :_type");
949949
assertQuery("select te from TestEntity te where te.type = :type");
950950
}
951+
952+
@Test // GH-3061
953+
void alternateNotEqualsOperatorShouldWork() {
954+
assertQuery("select e from Employee e where e.firstName != :name");
955+
}
951956
}

0 commit comments

Comments
 (0)