Description Repo to reproduced the issue chlrbgh89/hibernate-batch-size-bug Post about this issue [ @BatchSize with @ManyToMany does not work as expected when migrating 5 -> 6|https://discourse.hibernate.org/t/batchsize-with-manytomany-does-not-work-as-expected-when-migrating-5-6/7116] @BatchSize with @ManyToMany does not work as expected when migrating 5 -> 6 Summary When using @BatchSize with @ManyToMany in Hibernate 5.6.14.Final, it generated queries: ``` Hibernate: select article0_.id as id1_0_, article0_.category_id as category2_0_ from article article0_ order by article0_.id DESC limit ? Hibernate: select tags0_.article_id as article_1_1_1_, tags0_.tags_id as tags_id2_1_1_, tag1_.id as id1_2_0_, tag1_.name as name2_2_0_ from article_tags tags0_ inner join tag tag1_ on tags0_.tags_id=tag1_.id where tags0_.article_id in (?, ?, ?, ?, ?) ``` However In Hibernate 6.1.6: ``` Hibernate: select t1_0.article_id,t1_1.id,t1_1.name from article_tags t1_0 join tag t1_1 on t1_1.id=t1_0.tags_id where t1_0.article_id in(?,?,?,?,?) Hibernate: select t1_0.article_id,t1_1.id,t1_1.name from article_tags t1_0 join tag t1_1 on t1_1.id=t1_0.tags_id where t1_0.article_id in(?,?) Hibernate: select t1_0.article_id,t1_1.id,t1_1.name from article_tags t1_0 join tag t1_1 on t1_1.id=t1_0.tags_id where t1_0.article_id in(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ``` Hibernate 6.1.6 generated queries 2 more and binded data in each query were article-id that had empty tag list. And the values in IN clause at the last query was always generated as much as the size of @BatchSize. Environment
- Spring Boot 3.0.1
- Hibernate 6.1.6.Final
|