我搜索了一段时间,但找不到我想要的...

这是我的代码:

public List<MasseSalariale> findMasseSalarialeByCriteria(List<Section> sections,
  Integer exercice, List<BpCaEtats> etats) {

    List<String> etatString = new ArrayList<String>();
    for (BpCaEtats e : etats) {
      etatString.add(BpCaEtats.bpCaEtatToString(e));
    }

    CriteriaBuilder builder = this.getCriteriaBuilder();

    CriteriaQuery<MasseSalariale> query = builder.createQuery(MasseSalariale.class);
    Root<MasseSalariale> masseSalariale = query.from(MasseSalariale.class);
    Join<MasseSalariale, Etablissement> etablissement =
    masseSalariale.join(MasseSalariale_.etablissement);

    Predicate p1 = builder.equal(masseSalariale.get(MasseSalariale_.annee), exercice);

    Expression<List<Section>> exp2 = etablissement.get(Etablissement_.sections);
    Predicate p2 = exp2.in(sections);

    Expression<String> exp3 = masseSalariale.get(MasseSalariale_.etat);
    Predicate p3 = exp3.in(etatString);

    query.select(masseSalariale).where(builder.and(p1, p2, p3));

    return this.find(query);

}


基本上,我需要知道参数中的节列表中是否包含来自实现的节列表中的一个(至少)值。但是我认为谓词p2是错误的...

最佳答案

使用ListJoin,效果很好:

ListJoin<Etablissement, Section> sectionsEtab = etablissement.join(Etablissement_.sections);
Predicate p2 = sectionsEtab.in(sections);


谢谢

10-04 10:21