@ManyToOne associations not loaded correctly with default EAGER and batch fetch property set when using TypedQuery.resultStream

Description

When the following propert is set in persistence.xml to a value greater than 1

<property name="hibernate.default_batch_fetch_size" value="2" />

Then,

In a graph with a Parent-Child relationship, where the Child has a @ManyToOne to Parent entity, with default fetch EAGER. Then when

Child entities are loaded by an HQL query using the resultStream method, the parent entity is not mapped on any of the elements returned to the stream.

See attached test case proving the way it worked in Hibernate 5, and the subsequent fault in 6.

Workaround 1: Switch to @ManyToOne(fetch=FetchType.LAZY)

Attachments

1

Activity

Show:

Frode Carlsen August 16, 2022 at 11:24 AM

It would seem BatchEntitySelectFetchInitalizer#endLoading ( ) method is not called when invoking TypedQuery#getResultStream().

Thus the associated @ManyToOne entities are not set.

When invoking TypedQuery#getResultList() this works as expected.

Fixed

Details

Assignee

Reporter

Labels

Worked in

Components

Fix versions

Affects versions

Priority

Created August 16, 2022 at 11:00 AM
Updated September 8, 2022 at 1:50 PM
Resolved August 24, 2022 at 8:08 AM