From 60e29defe8fa45ffc1d573008a1a708ae10ae501 Mon Sep 17 00:00:00 2001 From: Josefina Revilla Date: Wed, 13 Sep 2023 17:50:57 -0300 Subject: [PATCH] Check for null predicates on queryItems --- .../src/main/java/org/jpos/ee/DBManager.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java b/modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java index ee69569f75..adde312708 100644 --- a/modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java +++ b/modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java @@ -27,6 +27,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Stream; public class DBManager { @@ -265,9 +266,16 @@ protected final CriteriaQuery createCriteriaQuery(boolean internalFilters, DB CriteriaQuery query = createCriteriaQuery(internalFilters, (DBFilter) null); CriteriaBuilder cb = db.session().getCriteriaBuilder(); Root root = query.from(clazz); - - return query.where(query.getRestriction() - , cb.and(Arrays.stream(filters).map(f -> f.createPredicate(cb, root)).toArray(Predicate[]::new))); + Predicate combinedPredicate = cb.and(Arrays.stream(filters) + .filter(f -> f != null) + .map(f -> f.createPredicate(cb, root)) + .toArray(Predicate[]::new)); + Predicate restriction = query.getRestriction(); + if (restriction != null) { + combinedPredicate = cb.and(restriction,combinedPredicate); + } + query.distinct(true); + return query.where(combinedPredicate); } private CriteriaQuery createQueryByParam(String param, Object value, boolean withFilter) {