我正在努力理解如何進行“NOT IN”之類的查詢。
基本上我有一個 root Agent。這些代理有一個 UUID id。
我想在我的謂詞串列中添加一個謂詞,以便在查詢中排除在給定 UUID 集合/集合中具有 ID 的任何代理。
不完全確定如何去做,但我看到有一個 IN 但沒有 NOT IN 但有一個isNotMember......
@Override
public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) {
root.fetch(Agent_.TAGS, JoinType.LEFT);
query.distinct(true);
List<Predicate> predicateList = new ArrayList<>();
if(!excludedAgents.isEmpty()){
// Excluded Agents is a Set<UUID> of the Agent Ids to exclude.
Predicate notMember = criteriaBuilder.isNotMember(????);
predicateList.add(notMember);
}
//More predicates here added....
return criteriaBuilder.and(predicateList.toArray(new Predicate[0]));
}
感謝您的任何幫助!
uj5u.com熱心網友回復:
isMember/isNotMember 用于檢查某個物體是否不屬于 toMany 關系。
你正在尋找的是
builder.not(root.get("id").in(uuids))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/513443.html
