时,使用标准API时,我总是得到相同的错误无效键错误:JPA:使用标准API
Local Exception Stack:
Exception [EclipseLink-6075] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.QueryException
Exception Description: Object comparisons can only use the equal() or notEqual() operators. Other comparisons must be done through query keys or direct attribute level comparisons.
Expression: [
Relation operator LIKE
Query Key rootId
Base de.uni.entities.Diary
Constant Testaccount]
Query: ReportQuery(referenceClass=Diary)
与标准API的代码如下:
....
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<User> cq = cb.createQuery(User.class);
// Restrictions
Predicate[] predicate = new Predicate[1];
// From-clause
Root<User> root2R = cq.from(User.class);
predicate[0] = cb.like(root2R.<String> get("rootId"), id);
Join<Clazz, Diary> friends2R;
friends2R = root2R.join("diaries");
cq.where(predicate);
// Select-clause
cq.select((Selection<? extends Clazz>) friends2R);
Query query = getEm().createQuery(cq);
List<Object> data = query.getResultList();
return data;
}
由于以下两行存在问题: “加入好友2R; friends2R = root2R.join(”diaries“);”
如果没有映射(使用调整后的select-clause),我会使用拟合rootId得到搜索的用户,这样就不会出现错误。但是现在我想将用户映射到日志并显示用户实体的所有日记。但它总是以前面的错误结束。无论我使用“喜欢”还是“平等”,它都不起作用。
generell代码不应该有错误,因为我已经使用相同的代码来获取所有映射的用户用户(多对多关系)=>没有问题。
我只是不明白,为什么会出现这个错误,特别是为什么它提到日记为基础,虽然用户应该被提及为基类......并且该ID也是正确的,并且也出现在数据库...
我真的希望你能帮助我,在此先感谢!