I can confirm this still happens with 5.0.2.Final.
This fails with the error message above:
public boolean anyPendingExpenses() {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Boolean> cq = cb.createQuery(Boolean.class);
Root<Expense> expense_ = cq.from(Expense.class);
return getEntityManager().createQuery(
cq.distinct(true).where(
cb.equal(expense_.get("status"), Expense.Status.Submitted)
).multiselect(
cb.selectCase()
.when(cb.gt(cb.count(expense_), cb.literal(0L)), cb.literal(true))
.otherwise(cb.literal(false))
)
).getSingleResult();
}
This ugly workaround works:
public boolean anyPendingExpenses() {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Expense> expense_ = cq.from(Expense.class);
return getEntityManager().createQuery(
cq.distinct(true).where(
cb.equal(expense_.get("status"), Expense.Status.Submitted)
).multiselect(
cb.selectCase()
.when(cb.gt(cb.count(expense_), cb.literal(0L)), cb.literal(1L))
.otherwise(cb.literal(0L))
)
).getSingleResult() > 0;
}
I can provide a simple Maven project with my sample domain model and test suite if useful.
|