从Hibernate 4.2.6迁移到EclipseLink 2.4.2(或2.5.1),以前很多标准查询现在突然被EclipseLink分解:
例如:
Exception Description: Invalid query key [
Query Key posts Base com.comax.model.mailing.Post]
in expression.Query: ReportQuery(referenceClass=Post )
其中Point
实体与Post
具有单向1-N关系。
查询
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Post> q = cb.createQuery(Post.class);
Root<Point> root = q.from(Point.class);
Join<Point, Post> p1 = root.join("posts", JoinType.INNER);
Path<String> city = p1.get("city");
q.select(p1).distinct(true).where(cb.like(city, "L%"));
TypedQuery<Post> tq = em.createQuery(q);
List<Post> results = tq.getResultList();
错误消息让我非常困惑。这些Post
和Point
实体都从Base
Query Key posts Base ...
实体继承(JOINED策略)
然而,JPQL等价
results = em.createQuery(
"SELECT DISTINCT post FROM Point p JOIN p.posts post WHERE post.city LIKE 'L%' ORDER BY post.city",
Post.class).getResultList();
按预期运行。
我如何实现这一目标?或者我错过了什么?在标准查询方面,EclipseLink是否有特定的东西?