I'm working on a Recipe application in Java, using JPA. I need to create a findBy method to find a Recipe by Ingredient id. I tried:
List<Recipe> findByRecipeIngredientsIngredientIdEqual(Long ingredientId);
But it doesn't work
Here are the classes:
public class Recipe {
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true)
private List<RecipeIngredient> recipeIngredients = new ArrayList<>();
}
public class RecipeIngredient {
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("ingredientId")
private Ingredient ingredient;
}
public class Ingredient {
private Long id;
private String name;
}