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