在我们的数据库中,我们有缓存系统,它对查询绑定参数敏感。
我有以下查询创建:
@Override
public Predicate toPredicate(Root<Position> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
query.distinct(true);
final Collection<Predicate> predicates = new ArrayList<>();
Join<Position, ManagersPositions> managersPositionsJoin = root.join("managersPositions", JoinType.INNER);
Predicate managerPredicate = criteriaBuilder.equal(managersPositionsJoin.get("managerId"), managerId);
predicates.add(managerPredicate);
if (onlyDirect) {
Predicate equalsDirect = criteriaBuilder.equal(managersPositionsJoin.get("isDirect"), true);
predicates.add(equalsDirect);
}
return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
}
它产生以下查询:
select
distinct position0_.id as id1_69_0_,
...
where managerspo1_.manager_id=22
and managerspo1_.is_direct=?
我必须发送带有 2 个绑定参数的请求,例如:
where managerspo1_.manager_id=?
and managerspo1_.is_direct=?
如何解决第一个“?”的问题?
牛魔王的故事
吃鸡游戏
相关分类