如何在有两个条件的情况下传递jpql查询?
这是我的例子:我想找到"档案"的列表
where DEPI2 = 2 and typedossier = urgent
同时我想查找档案清单
where DEPID = 2 and d2.dateCreation <:fiveDaysAhead2
这是我的功能
public List<Dossier> getDossierFindAllParDepartementMidandUrgen() {
Calendar myFiveDaysAhead2;
myFiveDaysAhead2 = Calendar.getInstance();
myFiveDaysAhead2.add(Calendar.DATE, -5);
TypedQuery<Dossier> query2;
query2 =
em.createQuery("SELECT d2 FROM Dossier d2 WHERE d2.depid =:DEPID AND d2.typeDossier = :tpd2 OR " +
"d2.dateCreation <:fiveDaysAhead2", Dossier.class);
query2.setParameter("DEPID","2");
query2.setParameter("tpd2","Urgent");
query2.setParameter("fiveDaysAhead2", myFiveDaysAhead2, TemporalType.TIMESTAMP);
return query2.getResultList();
}
在我的案例中,它找到了所有档案where d2.dateCreation <:fiveDaysAhead2
这意味着即使列出depid = 1
答案 0 :(得分:0)
query2 = em.createQuery(“SELECT d2 FROM Dossier d2 WHERE(d2.depid =:DEPID AND d2.typeDossier =:tpd2)OR”+ “(d2.dateCreation&lt;:fiveDaysAhead2 AND d2.depid =:DEPID)”,Dossier.class);