title: Spring Data JPA - find by name of field in collection
body: <p>Two days of thinking and searching and any result - internet and documentation do not answer my question.</p>
  
  <p>I need to construct a Jpa Repository method name to <strong>get</strong> a <strong><code>Set&lt;Recipe&gt;</code></strong> from database, <strong>by</strong> field of <code>Ingredient</code> ,<strong><code>ingrName</code></strong>. I am also using a join table and entity <code>RecipeIngredient</code> to store the amount of each ingredient in the Recipe using <code>RecipeIngredient</code></p>
  
  <p>Help, please.</p>
  
  <p><em>Thanks!</em></p>
  
  <p>I try to make something like this:</p>
  
  <pre><code>package com.pck.repository;
  
  import com.pck.Recipe;
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.stereotype.Repository;
  
  import java.util.Set;
  
  @Repository
  public interface RecipeRepository extends JpaRepository&lt;Recipe, Integer&gt; {
  
      public Set&lt;Recipe&gt; findAllByRecipeIngrs_Ingredient_IngrNameIn(Collection&lt;String&gt; ingredientNames)
  
  }
  
  </code></pre>
  
  <p>But it does'nt works.</p>
  
  <p>Recipe:</p>
  
  <pre><code>package com.pck.entity;
  
  import javax.persistence.*;
  import java.util.*;
  
  @Entity
  @Table(name="recipes")
  public class Recipe {
  
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true, mappedBy = "recipe")
      private Set&lt;RecipeIngredient&gt; recipeIngrs;
  
      public Recipe() {}
  
      public Set&lt;RecipeIngredient&gt; getRecipeIngrs() {
          return ingredients;
      }
      public void setRecipeIngrs(Set&lt;RecipeIngredient&gt; recipeIngrs) {
          this.recipeIngrs = recipeIngrs;
      }
  
      // ... other fields, constructors, getters, setters
  }
  </code></pre>
  
  <p>RecipeIngredient:</p>
  
  <pre><code>package com.pck.entity;
  
  import javax.persistence.*;
  import java.util.Objects;
  
  @Entity
  @Table(name="recipe_ingredient")
  public class RecipeIngredient {
  
      @JsonIgnore
      @ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.REFRESH})
      @JoinColumn(name = "recipe_id")
      private Recipe recipe;
  
      @ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.REFRESH})
      @JoinColumn(name = "ingredient_id")
      private Ingredient ingredient;
  
      @Column(name = "ingredient_amount_grams")
      private double ingredientAmountGrams;
  
      public RecipeIngredient() {}
  
      public Recipe getRecipe() {
          return recipe;
      }
      public void setRecipe(Recipe recipe) {
          this.recipe = recipe;
      }
  
      public Ingredient getIngredient() {
          return ingredient;
      }
      public void setIngredient(Ingredient ingredient) {
          this.ingredient = ingredient;
      }
  
      public double getIngredientAmountGrams() {
          return ingredientAmountGrams;
      }
      public void setIngredientAmountGrams(double ingredientAmountGrams) {
          this.ingredientAmountGrams = ingredientAmountGrams;
      }
  
      // ... other fields, constructors, getters, setters
  
  }
  </code></pre>
  
  <p>Ingredient:</p>
  
  <pre><code>package com.pck.entity;
  
  import javax.persistence.*;
  import java.util.*;
  
  @Entity
  @Table(name="ingredient")
  public class Ingredient{
  
      @Column(name="ingr_name")
      private String ingrName;
  
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true, mappedBy = "ingredient")
      private Set&lt;RecipeIngredient&gt; recipeIngrs;
  
      public Ingredient() {}
  
      public String getIngrName() {
          return ingrName;
      }
      public void setIngrName(String ingrName) {
          this.ingrName = ingrName;
      }
  
      public Set&lt;RecipeIngredient&gt; getRecipeIngrs() {
          return recipeIngrs;
      }
      public void setRecipeIngrs(Set&lt;RecipeIngredient&gt; recipeIngrs) {
          this.recipeIngrs = recipeIngrs;
      }
  }
  </code></pre>