title: spring data jpa find all by example nested collection property
body: <p>I have two objects. The company that can have multiple nested addresses.</p>
  
  <pre><code>@Entity
  @Data
  @Table(name = "company")
  public class Company {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id")
      private Long id;
  
      @Column(name = "name")
      private String name;
  
      @Column(name = "phone")
      private String phone;
  
      @OneToMany(mappedBy = "company", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
      private List&lt;Address&gt; addresses;
  }
  </code></pre>
  
  <p>Address class looks like this: </p>
  
  <pre><code>@Data
  @Entity
  @Table(name = "address")
  @ToString(exclude = "company")
  public class Address {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id")
      private Long id;
  
      @Column(name = "postal_code")
      private String postalCode;
  
      @Column(name = "city")
      private String city;
  
      @Column(name = "street")
      private String street;
  
      @JsonIgnore
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "company_id")
      private Company company;
  }
  </code></pre>
  
  <p>I want somehow if it's possible, make a dynamic query that searches through the nested collection property. I made a search method which uses example matcher but the result is wrong. Every time I got everything from DB, not only company with address postal code that I'm looking for.</p>
  
  <p>My search method looks like this:</p>
  
  <pre><code>@PostMapping("/search")
      public List&lt;Company&gt; search(@RequestBody final Company company){
          return companyRepository.findAll(Example.of(company,
                  ExampleMatcher.matchingAny()
                          .withIgnoreNullValues()
                          .withIgnorePaths("id")
                          .withStringMatcher(ExampleMatcher.StringMatcher.STARTING)));
      }
  </code></pre>
  
  <p>In my database, I have two objects and this is the result of the search: 
  <a href="https://i.stack.imgur.com/wXer3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wXer3.png" alt="enter image description here"></a></p>
  
  <p>As you can see I received everything from DB instead of the only first company which address postal code starts with 1.</p>