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 an parent instance with one or many children, Hibernate returns a random number of entities.
Parent: {code} @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; {code}
Child: {code} @Id @Column(name = "CHILD_ID") private Long id;
@Column(name = "PARENT_ID") private Long parentId;
@Column(name = "CREATED_ON") private ZonedDateTime createdOn; {code}
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 up to with any verion lower than 5.3.X this worked 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).
|
|