假设我有以下代码:
@Embeddable
Class Xyz { // has only one field
private String value;
}
@Entity
Class B {
@Embedded
private Xyz xyz;
}
@Entity
Class C {
private B b;
}
现在我的CDao
方法 - getAllByXyz(List<String> values)
我希望从c.b.xyz.value
位于values
的数据库中获取所有C条目。这是我得到的:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<C> q = cb.createQuery(C.class);
Root<C> r = q.from(C.class);
q.select(r);
Join<C, B> join = r.join(C_.b);
Expression<String> e = r.get(B_.xyz);
Predicate p = e.in(values);
q.where(p);
return em.createQuery(q).getResultList();
错误说Object comparisons can only use the equal() or notEqual() operators.
据我所知,Xyz
类和value
字段存在问题。我该如何解决这个问题?