Skip to content

Commit d2e1afd

Browse files
committed
Fix NEGATING_SIMPLE_PROPERTY to use IS NOT NULL when argument is null
When a query method uses NEGATING_SIMPLE_PROPERTY and the argument is null, the generated query should now use `IS NOT NULL` instead of `<>`. This ensures consistent behavior when handling null values across queries. Changes: - Updated `JpaQueryCreator` to handle null arguments in `NEGATING_SIMPLE_PROPERTY` by rewriting `<>` to `IS NOT NULL`. Closes spring-projects#3675
1 parent 6255a0c commit d2e1afd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,10 @@ public Predicate build() {
311311
return expression.isIsNullParameter() ? path.isNull()
312312
: builder.equal(upperIfIgnoreCase(path), upperIfIgnoreCase(expression.getExpression()));
313313
case NEGATING_SIMPLE_PROPERTY:
314-
return builder.notEqual(upperIfIgnoreCase(getTypedPath(root, part)),
315-
upperIfIgnoreCase(provider.next(part).getExpression()));
314+
ParameterMetadata<Object> negatedExpression = provider.next(part);
315+
Expression<Object> negatedPath = getTypedPath(root, part);
316+
return negatedExpression.isIsNullParameter() ? negatedPath.isNotNull()
317+
: builder.notEqual(upperIfIgnoreCase(negatedPath), upperIfIgnoreCase(negatedExpression.getExpression()));
316318
case IS_EMPTY:
317319
case IS_NOT_EMPTY:
318320

0 commit comments

Comments
 (0)