没有相关对象时,ElementCollection上的LazyLoadingException

时间:2016-05-13 13:26:16

标签: java spring-data jpql

我的关系定义如下:

@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "recipe_type", joinColumns = @JoinColumn(name = "recipe_id"))
@Column(name = "type")
@OrderColumn(name = "sort_order")
private List<String> types;

我尝试使用JPQL进行检索:

@Query("SELECT r FROM MealPlanWeekRecipe r " +
        "LEFT JOIN FETCH r.recipe " +
        "LEFT JOIN FETCH r.recipe.types " +
        "LEFT JOIN FETCH r.mealPlan " +
        "WHERE r.id.weekId = :week_id " +
        "AND r.id.mealPlanId IN :inclList")
LinkedHashSet<MealPlanWeekRecipe> findByIdWeekIdAndIdMealPlanIdInEagerly(
        @Param("week_id") Long weekId,
        @Param("inclList") Collection<Long> mealPlanIds);

当有人没有任何类型且我尝试访问它时,有人可以解释为什么我有LazyLoadingException吗?至少它不应该是空的,还是空列表?

0 个答案:

没有答案