From 062c3cd724203f6a781203bcbde1782cc1ca3362 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 1 Sep 2021 18:09:55 +0200 Subject: [PATCH] Make use of distinct predicate in envers --- .../internal/tools/query/Parameters.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java index a285c87eb1..55a0814fb4 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java @@ -296,14 +296,19 @@ public class Parameters { * @param addAliasRight Whether to add the alias to the right property. */ public void addWhereOrNullRestriction(String left, boolean addAliasLeft, String op, String right, boolean addAliasRight) { - // apply the normal addWhere predicate - final Parameters sub1 = addSubParameters( "or" ); - sub1.addWhere( left, addAliasLeft, op, right, addAliasRight ); + if ( "=".equals( op ) ) { + addWhere( left, addAliasLeft, " is not distinct from ", right, addAliasRight ); + } + else { + // apply the normal addWhere predicate + final Parameters sub1 = addSubParameters( "or" ); + sub1.addWhere( left, addAliasLeft, op, right, addAliasRight ); - // apply the is null predicate for both join properties - final Parameters sub2 = sub1.addSubParameters( "and" ); - sub2.addNullRestriction( left, false ); - sub2.addNullRestriction( right, false ); + // apply the is null predicate for both join properties + final Parameters sub2 = sub1.addSubParameters( "and" ); + sub2.addNullRestriction( left, false ); + sub2.addNullRestriction( right, false ); + } } private void append(StringBuilder sb, String toAppend, MutableBoolean isFirst) {