I have the table below:
I want to form a query with the following rules: Get product1 where Type is not type1 and not type2 and Flavor is not flavor1.
Type can be type1, type 2 or null.
I formed my query like this:
CriteriaBuilder cb = this.getEntityManager().getCriteriaBuilder();
CriteriaQuery<Product> searchQuery = cb.createQuery(Product.class);
Root<Product> u = searchQuery.from(Product.class);
List<Predicate> predicates = new ArrayList<Predicate>();
predicates.add(cb.and(cb.equal(u.get("product"),"product1"),cb.isNull(u.get("type")),cb.notEqual(u.get("flavor"), "flavor1")));
The problem is that this query returns nothing… Am I missing something? Please note that my question refers to the logic and not to the syntax, as the syntax is checked by forming simpler queries that returned some dummy results. Thank you!