【发布时间】:2021-10-22 20:06:41
【问题描述】:
我正在使用 JPA 编写 Java 中的 Recipe 应用程序。我需要创建一个 findBy 方法来按成分 ID 查找食谱。我试过了:
List<Recipe> findByRecipeIngredientsIngredientIdEqual(Long ingredientId);
但它不起作用
以下是课程:
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;
}
【问题讨论】:
标签: java spring-boot jpa spring-data-jpa spring-data