Skip to content

Commit 3257368

Browse files
committed
Support alternative NOT EQUALS operators in HQL.
Hibernate also supports "!=" and "^=" as NOT EQUALS operators. See #2970
1 parent 4e9c102 commit 3257368

File tree

2 files changed

+18
-1
lines changed
  • spring-data-jpa/src

2 files changed

+18
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,9 @@ expressionOrPredicate
533533
;
534534

535535
// https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_User_Guide.html#hql-relational-comparisons
536+
// NOTE: The TIP shows that "!=" is also supported. Hibernate's source code shows that "^=" is another NOT_EQUALS option as well.
536537
relationalExpression
537-
: expression op=('=' | '>' | '>=' | '<' | '<=' | '<>' ) expression
538+
: expression op=('=' | '>' | '>=' | '<' | '<=' | '<>' | '!=' | '^=' ) expression
538539
;
539540

540541
// https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_User_Guide.html#hql-between-predicate

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

+16
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,22 @@ WHERE TYPE(e) <> Exempt
564564
""");
565565
}
566566

567+
@Test // GH-2970
568+
void alternateNotEqualsShouldAlsoWork() {
569+
570+
assertQuery("""
571+
SELECT TYPE(e)
572+
FROM Employee e
573+
WHERE TYPE(e) != Exempt
574+
""");
575+
576+
assertQuery("""
577+
SELECT TYPE(e)
578+
FROM Employee e
579+
WHERE TYPE(e) ^= Exempt
580+
""");
581+
}
582+
567583
@Test
568584
void theRest5() {
569585

0 commit comments

Comments
 (0)