Support alternative NOT EQUALS operators in HQL.

Hibernate also supports "!=" and "^=" as NOT EQUALS operators.

See #2970
Original Pull Request #2972
This commit is contained in:
Greg L. Turnquist
2023-05-23 08:21:27 -05:00
parent e973c275ed
commit 6d56a2525c
2 changed files with 18 additions and 1 deletions

View File

@@ -533,8 +533,9 @@ expressionOrPredicate
;
// https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_User_Guide.html#hql-relational-comparisons
// NOTE: The TIP shows that "!=" is also supported. Hibernate's source code shows that "^=" is another NOT_EQUALS option as well.
relationalExpression
: expression op=('=' | '>' | '>=' | '<' | '<=' | '<>' ) expression
: expression op=('=' | '>' | '>=' | '<' | '<=' | '<>' | '!=' | '^=' ) expression
;
// https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_User_Guide.html#hql-between-predicate

View File

@@ -564,6 +564,22 @@ class HqlQueryRendererTests {
""");
}
@Test // GH-2970
void alternateNotEqualsShouldAlsoWork() {
assertQuery("""
SELECT TYPE(e)
FROM Employee e
WHERE TYPE(e) != Exempt
""");
assertQuery("""
SELECT TYPE(e)
FROM Employee e
WHERE TYPE(e) ^= Exempt
""");
}
@Test
void theRest5() {