OneToMany with referencedColumnName returns too many entities
Description
Attachments
1
- 23 Oct 2018, 10:20 AM
caused by
Activity
Show:
Former user February 19, 2019 at 5:53 AM
Fixed in 5.3 branch as well.
Former user January 8, 2019 at 3:26 AM
@Guillaume Smet, I reverted https://hibernate.atlassian.net/browse/HHH-12594#icft=HHH-12594 and https://hibernate.atlassian.net/browse/HHH-12556#icft=HHH-12556 (HHH-12556 had conflicts) and the test passes.
Let me know if you'd like me to look into it.
Former user January 8, 2019 at 2:33 AM
After commenting out the following, the test passes:
<property name="hibernate.default_batch_fetch_size">64</property>
Guillaume Smet January 7, 2019 at 1:06 PM
@Former user if it worked in 5.2, it looks like a pretty bad regression, could you take a look to check if the test case is legit?
Guillaume Smet January 7, 2019 at 1:05 PM
Just saw you assigned it to me. Please don't do that because I'm not working on this issue and it prevents others to take a look at it.
Thanks.
Fixed
Created October 23, 2018 at 10:21 AM
Updated February 19, 2019 at 5:53 AM
Resolved February 19, 2019 at 5:53 AM
There seems to be a regression in 5.3.X from previous versions when using a OneToMany relation with referencedColumnName and EAGER fetching (it does not happen with LAZY fetching).
When fetching a parent instance with one or many children, Hibernate returns a random number of entities.
Parent:
@Id @Column(name = "PARENT_ID") private Long id; @OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }) @JoinColumn(name = "PARENT_ID", referencedColumnName = "PARENT_ID") @OrderBy("createdOn desc") private List<Child> children;
Child:
@Id @Column(name = "CHILD_ID") private Long id; @Column(name = "PARENT_ID") private Long parentId; @Column(name = "CREATED_ON") private ZonedDateTime createdOn;
When adding 2 children and 1 parent to the database, we end up with a List of 26 children in the parent.
This is fairly old code and could be done much better but with any version lower than 5.3.X it works fine.
This has been tested with Postgresql, Oracle and H2 (in memory) and is always reproducible.
I have attached a test (maven setup).