I am trying convert this JPA QL to criteria builder. JBoss 6.0.
\"SELECT ba FROM BankAccount ba WHERE ba.balance >= :amt ORDER BY ba.ownerName ASC\"
Well, I finally found the right way to call the gt() method. Here is the complete solution. Fully tested in JBoss 6.
public List findWithBalance(int amount) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(BankAccount.class);
Root from = cq.from(BankAccount.class);
ParameterExpression balance = cb.parameter(Integer.class);
cq.select(from);
//Here is the trick!
Predicate predicate = cb.gt(from. get("balance"), balance);
cq.where(predicate);
cq.orderBy(cb.asc(from.get("ownerName")));
TypedQuery query = em.createQuery(cq);
query.setParameter(balance, amount);
return query.getResultList();
}