Skip to content

Commit

Permalink
Support alternative NOT EQUALS operators in HQL.
Browse files Browse the repository at this point in the history
Hibernate also supports "!=" and "^=" as NOT EQUALS operators.

See #2970
  • Loading branch information
gregturn committed May 23, 2023
1 parent 4e9c102 commit 3257368
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,22 @@ WHERE TYPE(e) <> Exempt
""");
}

@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() {

Expand Down

0 comments on commit 3257368

Please sign in to comment.