I had following entities in my project:
AccountGroupAccountItemAccountSegment
With folowing relations:
AccountGrouphasList<AccountItem>AccountItemhadList<AccountSegment>
and everything worked fine.
When I changed last relation to:
AccountItemhasSet<AccountSegment>
AccountGroup object read from database looks strange. If given AccountItem had three AccountSegments, then I have three the same AccountItems in AccountGroup.
A shot from debugger can possibly tell it better than I can:

As you can see, accountMapperItems list has four positions instead of two. First pair is a duplicate each having the same variables. (second is similar, not shown on screenshot).
Below I paste entities code fragments:
class AccountGroup {
...
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "group")
private List<AccountItem> accountMapperItems;
....
}
class AccountItem {
...
@ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH, CascadeType.MERGE })
@JoinTable(
joinColumns={@JoinColumn(name="ACCOUNT_ITEM_ID", referencedColumnName="ID")},
inverseJoinColumns={@JoinColumn(name="SEGMENT_ID", referencedColumnName="ID")})
private Set<Segment> segmentSet;
@ManyToOne
private AccountGroup group;
...
}
AccountSegment does not have any links.
Does anyone know why is it retriving accountMapperItems list one position per AccountSegment?
The problem is not duplicate entries in jointable! I have double checked it.
Update
@Fetch (FetchMode.SELECT)
solved the case, further explanations are available in post mentioned in the answer.