Query#scroll fetches only parts of ManyToMany collections on join fetch

Description

Description

If you have an entity A with a many-to-many relationship to another entity B and try to scroll over a result by "SELECT DISTINCT a FROM A a LEFT JOIN FETCH a.b" then only some elements of b are returned. If you do a list on the query everything is returned. See example project attached as zip.

The documentation states that differently:
— The fetch construct cannot be used in queries called using iterate() (though scroll() can be used) (http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#queryhql-joins)

Information about the example project

In the example project there are 2 entities Vehicle and Tag with a many-to-many relationship.

The Main program inserts 20 vehicles: 10 with 2 Tags "TAG1" and "TAG2", 10 without any tags.

After that the the query "SELECT DISTINCT v FROM Vehicle v LEFT JOIN FETCH v.vehicleTags ORDER BY v.id" is executed via scroll and list and the results are logged.

You can see that the scroll result does only show both tags for the first vehicle, the rest have only one tag. The list result shows both tags on all 10 tagged vehicles.

Environment

Reproduced on 3.3.2, 3.5.0-Final and 3.5.2-Final

Activity

Show:
Brett Meyer
April 7, 2014, 5:47 PM

In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.

If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.

Thank you!

Christian Köberl
April 9, 2014, 7:37 AM

Test case for all Hibernate Version 3.6 - 4.3.
Unpack ZIP then run with "mvn verify -Dhibernate.version={Hibernate version}" (default version is 4.3.5.Final)

Christian Köberl
April 9, 2014, 7:42 AM

Ticket may be closed - I ran the test case with the following Hibernate versions:

  • 3.6.10.Final - FAIL

  • 4.1.7.Final - FAIL

  • 4.1.8.Final - SUCCESS

  • 4.1.12.Final - SUCCESS

  • 4.2.12.Final - SUCCESS

  • 4.3.5.Final - SUCCESS

Seems this bug was fixed with 4.1.8.Final - so please close as fixed with fix version 4.1.8.Final!

Guillaume Smet
April 9, 2014, 7:43 AM

Hi Christian,

Thanks for your analysis!

Brett Meyer
April 9, 2014, 1:54 PM

, thanks for the testing – appreciate it!

, I'm marking this as CANNOT REPRODUCE. Thanks for the help with JIRA, but we don't typically add already-released versions as the "fixVersion".

Assignee

Unassigned

Reporter

Christian Köberl

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure