【发布时间】:2015-11-16 11:59:09
【问题描述】:
我有以下返回列表的 Criteria API 代码。
我想把它转换成List<myClass>
我该怎么做?
CriteriaQuery<Tuple> cq = cb.createTupleQuery();
Root<ProductCatalogue> pc = cq.from(ProductCatalogue.class);
Root<ProductList> al = cq.from(ProductList.class);
.......
.......
.......
Predicate[] predicates = new Predicate[predicateList.size()];
predicateList.toArray(predicates);
criteriaQuery.where(predicates);
TypedQuery<Tuple> typedQuery = getEntityManager().cq(criteriaQuery);
List<Tuple> tuple = typedQuery.getResultList();
理想情况下我愿意
List<Employee> emp = tuple
但是上面导致了不兼容的类型错误,我不知道我该如何转换。
【问题讨论】:
-
你真的需要元组吗?如果没有,为什么不直接创建
CriteriaQuery<Employee>?例如见here
标签: jpa tuples eclipselink jpa-2.0 criteria-api