我正在尝试将此 JPA QL 转换为标准生成器。JBoss 6.0。
"SELECT ba FROM BankAccount ba WHERE ba.balance >= :amt ORDER BY ba.ownerName ASC"
我根据几个教程编写了这段代码。
public List<BankAccount> findWithBalance(int amount) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BankAccount> cq = cb.createQuery(BankAccount.class);
Root<BankAccount> from = cq.from(BankAccount.class);
ParameterExpression<Integer> balance = cb.parameter(Integer.class);
cq.select(from);
Predicate predicate = cb.gt(from.get("balance"), balance);
cq.where(predicate);
cq.orderBy(cb.asc(from.get("ownerName")));
TypedQuery<BankAccount> query = em.createQuery(cq);
return query.getResultList();
}
但是,我在该行中遇到编译错误:
Predicate predicate = cb.gt(from.get("balance"), balance);
错误是:
The method gt(Expression<? extends Number>, Expression<? extends Number>) in the type CriteriaBuilder is not applicable for the arguments (Path<Object>, ParameterExpression<Integer>)