Pagination for polymorphic queries is not applied properly.

Description

Description

Given polymorphic entity hierarchy:

with 2 Left and 2 Right instances in the DB, the following Query:

should return 3 instances, but only returns 1.

 

There seem to be 2 problems in org.hibernate.query.sqm.internal.AggregatedSelectQueryPlanImpl
Problem 1
The query is split into 2, one for Left and one for Right and the pagination is applied on both these queries and then also on the merged result, skipping the offset 3 times.

Instead, the pagination should be applied on the merged result only (by AggregatedSelectQueryPlanImpl).

Problem 2
In one of the branches where AggregatedSelectQueryPlanImpl handles pagination while merging the partial results, it skips availableElements instead of elementsToSkip

Solution
Besides a unit test I’m also attaching a (possibly) fixed version of AggregatedSelectQueryPlanImpl. The parts I touched are preceded by a comment starting with // FIX

As I didn’t look deeper in the codebase, I’m not sure this is the best way to fix the issue, so I’m not creating a PR, but rather have you handle it properly.

Attachments

2

Activity

Show:

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Created April 20, 2024 at 2:40 PM
Updated April 20, 2024 at 2:40 PM