Problem with criteria [message #1074540] |
Sat, 27 July 2013 03:14 |
jake frog Messages: 8 Registered: July 2012 |
Junior Member |
|
|
Hello,
I am using the criteria below:
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Manufacturer> criteriaQuery = criteriaBuilder.createQuery(Manufacturer.class);
criteriaQuery.distinct(true);
Root<Manufacturer> mainRoot = criteriaQuery.from(Manufacturer.class);
Join joinProducts = mainRoot.join("products", JoinType.INNER);
Path<NickName> nickNames = joinProducts.get("nickNames");
Predicate noEmptyList = criteriaBuilder.isEmpty(nickNames.get("justList"));
// or if I use nickNames.get("justList").as(List.class) is the same result
criteriaQuery.where(criteriaBuilder.and(noEmptyList));
TypedQuery<Manufacturer> query = em.createQuery(criteriaQuery);
query.getResultList().size()// check the screen to see the result
but... that is not working. It is bringing me a result with not empty "justList", but in the code I added the predicated "criteriaBuilder.isEmpty".
In the screen it is possible to see a wrong result.
PS.: The same criteria works with Hibernate and OpenJPA. =/
PS2.: The created query is:
SELECT DISTINCT
t2.ID, t2.NAME
FROM
NICKNAME t0,
MANUFACTURER t2,
PRODUCT t1
WHERE
((SELECT
COUNT(t3.ID)
FROM
PRODUCT_NICKNAME t6,
MANUFACTURER_PRODUCT t5,
NICKNAME_DUMMY_LIST t4,
DUMMYENTITY t3
WHERE
(((t4.id = t0.ID) AND (t3.ID = t4.dummy_id)) AND (((t5.Manufacturer_ID = t2.ID) AND (t1.ID = t5.products_ID)) AND ((t6.Product_ID = t1.ID) AND (t0.ID = t6.nickNames_ID))))) = ?)
[Updated on: Sat, 27 July 2013 03:19] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03251 seconds