|
Prerequisites:
-
Two entities, A and B, have a many-to-many relationship
-
The link table has additional data, and is thus modeled as its own entity, C
-
C has a composite primary key which defines @ManyToOne relationships to A and B
-
A has a @OneToMany mapping to C using mappedBy. This @OneToMany mapping also defines cascade = CascadeType.ALL.
When using Session.refresh() on A, Hibernate gets stuck on an infinite loop, which eventually results in a StackOverflowError. A minimalistic test case that reproduces this problem is attached. The problem was first noticed with version 4.3.5.Final, but is also reproducible with 4.3.11.Final.
Workaround: Do not cascade the refresh operation. E.g. replace CascadeType.ALL with {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}
|