I recently started using the Criteria API because I need to make queries that would be very complex with HQL.
How do I use the AND
and OR
operators in queries with the Criteria API?
I recently started using the Criteria API because I need to make queries that would be very complex with HQL.
How do I use the AND
and OR
operators in queries with the Criteria API?
Would this be the syntax example you are looking for?
CriteriaQuery<Pet> cq = cb.createQuery(Pet.class);
Root<Pet> pet = cq.from(Pet.class);
cq.where(cb.equal(pet.get(Pet_.name), "Fido")
.and(cb.equal(pet.get(Pet_.color), "brown")));