title: How to search date field for a String using JPA Criteria API
body: <p>This is a question that spins off my other Question <a href="https://stackoverflow.com/questions/33149848/why-does-jpa-typedquery-throw-exception-parameter-value-did-not-match-exp/33151089#33151089">here</a> . I thought it would be best put as a different question after someone(<a href="https://stackoverflow.com/users/756146/franck">@Franck</a>) pointed me to <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate/hibernate-entitymanager/4.1.0.Final/org/hibernate/ejb/AbstractQueryImpl.java#370" rel="nofollow noreferrer">this link</a> and <a href="https://docs.oracle.com/javaee/6/api/javax/persistence/criteria/Expression.html#as(java.lang.Class)" rel="nofollow noreferrer">this one too</a>.</p>
  
  <p>I'm stumped on how to <strong>search for a string in a database Date column (in my case MySQL DATETIME) using the JPA Criteria API.</strong></p>
  
  <p>Here's what I've done;</p>
  
  <pre><code>CriteriaBuilder cb = em.getCriteriaBuilder();
  CriteriaQuery&lt;Client&gt; cq = cb.createQuery(Client.class);
  Root&lt;Client&gt; entity = cq.from(Client.class);
  cq.select(entity);
  
  List&lt;Predicate&gt; predicates = new ArrayList&lt;Predicate&gt;();
  predicates.add(cb.like(cb.lower(entity.get("dateJoined").as(String.class)), "%"+search.toLowerCase()+"%")); 
  
  cq.where(predicates.toArray(new Predicate[]{}));
  TypedQuery&lt;Client&gt; query = em.createQuery(cq); //&lt;--- Error gets thrown here
  return query.getResultList();
  </code></pre>
  
  <p>But it fails with the following exception;</p>
  
  <blockquote>
  <pre><code>java.lang.IllegalArgumentException: Parameter value [%10-2015%] did not
  match expected type [java.lang.Character]
  </code></pre>
    
    <p><em>where <code>10-2015</code> is the String being searched for;</em></p>
  </blockquote>
  
  <p>I'm stuck on how to go by achieving this. I need some help.</p>