Hello, I was trying to find a solution that would avoid using:
@OneToMany(fetch = FetchType.EAGER)
That's because I don't always want my relationship to be eager. I would like to use `join fetch` in my JPQL query when I need the relationship to be eager. I have a workaround which is as below:
public class OtmCustomer {
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "customer_id")
private List<OtmAccount> accounts = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "customer_id")
private Set<OtmAddress> addresses = new HashSet<>();
One of my collections has to be a Set (because a Set is not a Bag). Is it the proper way to work with it? Also, I don't understand why moving to a Set is fixing the issue. Any explanation would be welcome . Thanks! |