Hibernate Subselect vs Batch Fetching

前端 未结 2 1003
情书的邮戳
情书的邮戳 2020-12-29 09:14

Hibernate provides (at least) two options for getting around the N+1 query problem. The one is setting the FetchMode to Subselect, which generates a select with a IN-clause

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 09:35

    I found this article to be helpful. I believe batch-fetching can be applied on both the collection and the parent, while subselect can only be applied on a collection.

    In case of a fetching strategy for collections, a subselect will be executed once (because the batch-size is effectively infinity), while with batch-fetching the SQL statement might be executed multiple times.

提交回复
热议问题