title: JPA2: Case-insensitive like matching anywhere
body: <p>I have been using Hibernate Restrictions in JPA 1.0 ( Hibernate driver ). There is defined <code>Restrictions.ilike("column","keyword", MatchMode.ANYWHERE)</code> which tests if the keyword matching the column anywhere and it is case-insensitive. </p>
  
  <p>Now, I am using JPA 2.0 with EclipseLink as driver so I have to use "Restrictions" build-in JPA 2.0. I found <code>CriteriaBuilder</code> and method <code>like</code>, I have also found out how to make it matching anywhere ( although it is aweful and manual ), but still I haven't figured out how to do it case-insensitive.</p>
  
  <p>There is my current aweful solution:</p>
  
  <pre><code>CriteriaBuilder builder = em.getCriteriaBuilder();
  CriteriaQuery&lt;User&gt; query = builder.createQuery(User.class);
  EntityType&lt;User&gt; type = em.getMetamodel().entity(User.class);
  Root&lt;User&gt; root = query.from(User.class);
  
  // Where   
  // important passage of code for question  
  query.where(builder.or(builder.like(root.get(type.getDeclaredSingularAttribute("username", String.class)), "%" + keyword + "%"),
          builder.like(root.get(type.getDeclaredSingularAttribute("firstname", String.class)), "%" + keyword + "%"),
          builder.like(root.get(type.getDeclaredSingularAttribute("lastname", String.class)), "%" + keyword + "%")
          ));
  
  // Order By
  query.orderBy(builder.asc(root.get("lastname")),
              builder.asc(root.get("firstname")));
  
  // Execute
  return em.createQuery(query).
              setMaxResults(PAGE_SIZE + 1).
              setFirstResult((page - 1) * PAGE_SIZE).
              getResultList();
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <p>Is there any function like in Hibernate driver? </p>
  
  <p>Am I using the JPA 2.0 criteria correctly? This is awkward and uncomfortable solution in compare to Hibernate Restrictions.</p>
  
  <p>Or can anybody help me how to change my solution to be case-insensitive, please?</p>
  
  <p>Thanks a lot.</p>