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