Problem with criteria [message #899195] |
Mon, 30 July 2012 21:36  |
Eclipse User |
|
|
|
Hello.
The JPQL bellow bring me only one result, that is the correct result:
select distinct c from Car c join c.person p where p.dogs is empty The result is:
[Car name: Yellow Submarine]
But when I create the Criteria bellow:CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Car> criteriaQuery = criteriaBuilder.createQuery(Car.class);
Root<Car> mainRoot = criteriaQuery.from(Car.class);
criteriaQuery.select(mainRoot);
criteriaQuery.distinct(true);
Join<Person, Car> join = mainRoot.join("person", JoinType.INNER);
// Is this right?
criteriaQuery.where(criteriaBuilder.and(criteriaBuilder.isEmpty(join.get("dogs").as(List.class)))); The wrong result is given:[Car name: Black Horse, Car name: White Thunder, Car name: Herbie, Car name: Yellow Submarine]
It brings all the data from the database. Am I missing anything?
Thanks for the help.
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08020 seconds