0

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.

bemol
  • 381
  • 3
  • 18

1 Answers1

1

You need to use query.distinct(true)

Mihai Soloi
  • 373
  • 1
  • 12