Why spring data jpa not issuing JOIN query?

前端 未结 1 934
余生分开走
余生分开走 2021-01-05 22:04

I have created two entities Book and Book_Category with one-to-many relationship. When I issued BookCategoryRepository.findAll(), I ex

相关标签:
1条回答
  • 2021-01-05 22:20

    Hibernate uses by default a second query to retriev the child collection. One reason for this is a proper limit query. Otherwise, there would be more rows in the result set, than entities for the 1 side, if at least one has more than 1 child.

    There exists an annotation to change this behaviour in hibernate which is ignored by the Spring Data Jpa Repositories. The annotation is @Fetch(FetchMode.JOIN). You might consider How does the FetchMode work in Spring Data JPA if you really need this behaviour.

    0 讨论(0)
提交回复
热议问题