Trying to filter a list column with Jpa specification and CriteriaBuilder

Viewed 22

This is what I have so far, but it is obviously not working. I was thinking about creating a CriteriaBuilder.In for each of elements of the array from the column, but there has to be a better way to do it right? The code should give me elements that match the search [1,2] and disregard 3

if(!filterQuery.getNumbersToSearch().isEmpty()) {
                CriteriaBuilder.In<List<Integer>> inClause = criteriaBuilder.in(root.get("numbers")); // [1,2,3]
                for(Integer number : filterQuery.getNumbersToSearch()) { //[1,2]
                    inClause.value(number); 
                }
                predicates.add(inClause);
            }
    
0 Answers
Related