@BatchSize with @ManyToMany does not work as expected when migrating 5 -> 6

Description

from

I have the following entities.

Entity Models:

And DTO:

In Hibernate 5.6.14, when querying articles, it generated queries :

However In Hibernate 6.1.6:

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.

Test Code:

I expected executing queries same in both version, it wasn't.

 

Reproducer

reproducer:

reproducer Hibernate version is 6.1.6.Final

If you want to downgrade version to 5.6.14.Final, uncomment this code in build.gradle

Activity

Show:

Marco Belladelli January 25, 2023 at 2:18 PM

Hello, I did some tests and the solution for should solve your problem too: the query to retrieve the tags was executed just once with the 5 Article IDs - thanks to batching - and no more queries were triggered.

Fixed

Details

Assignee

Reporter

Worked in

Components

Fix versions

Affects versions

Priority

Created January 9, 2023 at 1:55 PM
Updated February 7, 2023 at 11:20 AM
Resolved January 25, 2023 at 4:04 PM