我想连接两个表并删除连接查询中的 on 子句以设置新的自定义 on 子句,但是我总是从“joinb”获得空谓词,因此无法与更多条件连接。 我的代码如下。
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<myClass> query = cb.createQuery(myClass.class);
Root<a> a = query.from(a.class);
Join<a, b> joinb = a.join("b", JoinType.INNER);
Predicate joinBOn = b.getOn();
b.on(cb.or(joinBOn, cb.or("condition1", "condition2")));
这里的问题是 joinBOn 始终为 null。 我是新人,所以我不知道发生了什么。
最佳答案
根据记录,getOn()
Return the predicate that corresponds to the ON restriction(s) on the join, or null if no ON condition has been specified.
在这种情况下,显然没有指定 ON 条件,因此预期为 null
。这不是问题,因为不需要获取当前的 ON 限制:
Predicate condition1 = ...
Predicate condition2 = ...
b.on(cb.or(condition1, condition2));
关于java - Criteria Builder 中的 Join 中的 getOn 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58531075/