title: Spring JPA Specifications Not In Query
body: <p>Here the IN criteria query using Spring JPA Specification is working fine. but I don't know how to use "NOT IN"..</p>
  
  <p>So How can i use the NOT IN criteria query using Spring JPA Specifications.</p>
  
  <pre><code>SearchSpecification&lt;User&gt; spec = new CommonSpecification&lt;Case&gt;(new SearchCriteria("client.id", Operator.NOT_IN, clientIdList));
  
  @Override
  public Predicate toPredicate(Root&lt;T&gt; root, CriteriaQuery&lt;?&gt; criteriaQuery, CriteriaBuilder criteriaBuilder) {
      Predicate predicate = null;
      switch (searchCriteria.getOperator()) {
  
      case IN:
          if (searchCriteria.getValue() instanceof List&lt;?&gt;) {
              predicate = getFieldPath(searchCriteria.getKey(), root)
                      .in(((List&lt;?&gt;) searchCriteria.getValue()).toArray());
          }
          break;
      case NOT_IN:
          //What to do???
          break;
      default:
          break;
  
      }
      return predicate;
  }
  
  
  private Path&lt;Object&gt; getFieldPath(String key, Root&lt;T&gt; root) {
      Path&lt;Object&gt; fieldPath = null;
      if (key.contains(".")) {
          String[] fields = key.split("\\.");
          for (String field : fields) {
              if (fieldPath == null) {
                  fieldPath = root.get(field);
              } else {
                  fieldPath = fieldPath.get(field);
              }
          }
      } else {
          fieldPath = root.get(key);
      }
      return fieldPath;
  }
  </code></pre>