Reputation: 395
I have a problem with join in CriteriaAPI.
I want to get the result with unique Forma
entities, but currently I get multiple entities (their number is equal to the number of Gniazdo
entities).
This is my code:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Forma> query = cb.createQuery(Forma.class);
Root<Forma> root = query.from(Forma.class);
Join<Forma, Gniazdo> socketJoin = root.join("gniazda", JoinType.INNER);
List<Predicate> predicates = new ArrayList<Predicate>();
predicates.add(root.get("dataUsuniecia").isNull());
predicates.add(socketJoin.get("dataUsuniecia").isNull());
Predicate[] conditions = predicates.toArray(new Predicate[predicates.size()]);
query.where(cb.and(conditions));
List<Forma> queryResult = em.createQuery(query).getResultList();
Please help.
Upvotes: 0
Views: 1295