Spring 数据 jpa 未选择所有记录

Spring data jpa not selecting all records

我是 Hibernate 的初学者,我不想弄清楚一些机制。 我有实体:

@Entity
@Table(name = "dish")
public class Dish implements Serializable {

   @ManyToMany(fetch = FetchType.LAZY)
   private List<Ingredient> ingredients;

   @ManyToOne(fetch = FetchType.LAZY)
   private Category category;
}

以及使用这种方法的存储库:

@Query("select d from Dish d join fetch d.ingredients")
    Set<Dish> getDishesWithIngredientsAndCategory();

而且我注意到,我通过这种方法检索 具有相关成分的菜肴。 所有道​​菜都不知道怎么弄,连配料都没有? 第二个问题是:是否可以在一个@Query 中合并获取两列?类似于:

@Query("select d from Dish d join fetch d.ingredients, d.category")

我尝试使用这样的查询,但我收到 QuerySelectionException: "d.category is not mapped".

That I'm retrieving by this method only Dishes, that have associated ingredients.

使用 Left Join 而不是加入:@Query("select d from Dish d left join fetch d.ingredients")

And second question is: is it possible to combine in one @Query fetch two columns? You can try this:

@Query("select d from Dish d join fetch d.ingredients join fetch d.category")