title: Spring Data JPA Specifications Calling
body: <p>I followed this tutorial to get Spring Data JPA Specifications: <a href="https://dzone.com/articles/using-spring-data-jpa-specification" rel="nofollow noreferrer">https://dzone.com/articles/using-spring-data-jpa-specification</a></p>
  
  <p>It worked to implement that for me, but I can't call the specifications methods to search for them. I want to have them in my SearchController:</p>
  
  <p><a href="https://imgur.com/a/rX1YWH7" rel="nofollow noreferrer"><img src="https://imgur.com/a/rX1YWH7" alt="This is the project"></a>
  Code:
  TelefonbuchSpecifications:</p>
  
  <pre><code>public static Specification&lt;Telefonbuch&gt; hasVorname(String vorname) {
      return (root, query, cb) -&gt; {
          return cb.equal(root.get(Telefonbuch_.vorname), "%"+vorname.toLowerCase()+"%");
      };
  }
  </code></pre>
  
  <p>And now I want to call this method in my SearchController (SucheController), but I don't know how.
  At the moment the method looks like this:
  SucheController:</p>
  
  <pre><code>   public void search(String vorname, String nachname, String telefonnummer, String handynummer) {  
      telefonbuch.setVorname(vorname);
      telefonbuch.setNachname(nachname);
      telefonbuch.setTelefonnummer(telefonnummer);
      telefonbuch.setHandynummer(handynummer);
  
      CriteriaBuilder builder = em.getCriteriaBuilder();
      CriteriaQuery&lt;Telefonbuch&gt; query = builder.createQuery(Telefonbuch.class);
      Root&lt;Telefonbuch&gt; root = query.from(Telefonbuch.class);
      List&lt;Predicate&gt; predicates = new ArrayList&lt;Predicate&gt;();
  
  
  
      if (!vorname.isEmpty()) {   
          //eintraege = telefonbuchRepository.findAll(hasVorname()); -&gt; does not work
          Predicate condition = builder.like(builder.lower(root.get(Telefonbuch_.vorname)), "%"+vorname.toLowerCase()+"%");
          predicates.add(condition);
      }
  ...
  query.select(root).where(predicates.toArray(new Predicate[predicates.size()]));
  </code></pre>