Multiple fetches with EAGER type in Hibernate with JPA

前端 未结 2 1058
北恋
北恋 2020-11-29 02:40

I have an entity which contains:

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = \"assessment\")
@OrderBy(value = \"order ASC\")
pr         


        
2条回答
  •  情歌与酒
    2020-11-29 02:51

    The root cause of the problem is that when Hibernate fetches SQL query results there is no simple way to tell which child element belongs to which collection. See this blog entry for more detailed explanation with an example. To summarize you have following workarounds:

    • Load each collection separately using subselect @Fetch(FetchMode.SELECT)
    • Force usage of list instead of bag by adding index column @IndexColumn(name="LIST_INDEX")
    • Use unordered collection like Set.

提交回复
热议问题