title: Case insensitive search with Predicate and Criteria API
body: <p>I have currently implemented a dynamic query builder that works perfectly if my query conditions are spelled correctly. Since this might not be always the case I need a solution that is flexible enough to take any variation of the condition, primarily supporting case insensitivity.</p>
  <p>Current specification's toPredicate method override code looks like this:</p>
  <pre><code>final List&lt;Predicate&gt; predicates = new ArrayList&lt;Predicate&gt;();
  
      Path&lt;String&gt; username = root.get(&quot;username&quot;);
      Path&lt;String&gt; agentCode = root.get(&quot;agentCode&quot;);
      Path&lt;EntityStatus&gt; status = root.get(&quot;status&quot;);
      Path&lt;String&gt; firstname = root.get(&quot;firstName&quot;);
      Path&lt;String&gt; lastname = root.get(&quot;lastName&quot;);
      Path&lt;String&gt; email = root.get(&quot;eMail&quot;);
  
  
  if(criteria.getUsername()!=null &amp;&amp; !criteria.getUsername().isEmpty()) {
        predicates.add(cb.equal(username, criteria.getUsername()));
      }
  
      if(criteria.getAgentCode()!=null &amp;&amp; !criteria.getAgentCode().isEmpty()) {
        predicates.add(cb.equal(agentCode, criteria.getAgentCode()));
      }
  
      if(criteria.getFirstName()!=null &amp;&amp; !criteria.getFirstName().isEmpty()) {
        predicates.add(cb.like(firstname, &quot;%&quot;+criteria.getFirstName()+&quot;%&quot;));
      }
  
      if(criteria.getLastName()!=null &amp;&amp; !criteria.getLastName().isEmpty()) {
        predicates.add(cb.equal(lastname, criteria.getLastName()));
      }
  
      if(criteria.getEMail()!=null &amp;&amp; !criteria.getEMail().isEmpty()) {
        predicates.add(cb.equal(email, criteria.getEMail()));
      }
  
      if(criteria.getStatus()!=null) {
        predicates.add(cb.equal(status, criteria.getStatus()));
      }
  
      return cb.and(predicates.toArray(new Predicate[predicates.size()]));
    }
  </code></pre>
  <p>And my repository interface that is being called from the service layer looks like this.</p>
  <pre><code>public interface UserRepo extends PagingAndSortingRepository&lt;User, Long&gt; {
       List&lt;User&gt; findAll(Specification spec);
  }
  </code></pre>