I'm trying to convert the following SQL to CriteriaBuilder code
SQL:
Code:
SELECT * FROM logging WHERE CONVERT(log_action, CHAR(100)) = 'delete'
log_action is defined as a varbinary(32).
CODE:
Code:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Logging> query = cb.createQuery(Logging.class);
Root<Logging> from = query.from(Logging.class);
Expression<Byte> path = from.get("logAction");
Expression<String> convertFunction = cb.function("CONVERT", String.class, path);
query.select(from);
Predicate predicate = cb.equal(convertFunction, "delete");
query.where(predicate);
return em.createQuery(query).getResultList();
Any ideas what I'm doing wrong?
Thanks,
Sean