1

I have a few entities which I need to use eager fetch. After browsing here it seems that this is a known problem when setting the fetch type to eager.

Is there a way of eliminating the duplicates? I can't use Sets because I am getting a lot of problem with some of the equals() and hashCode() (Some of the elements the only reason to recognize between them is the id, not a business key).

Right now I am using PrePersist and PostLoad to eliminate the duplicates, e.g.

@PostLoad
@PrePersist //FIXME best way to handle this?
public void removeDuplicates() {
    Set<Role> noDupesRoles = new HashSet<Role>();
    noDupesRoles.addAll(roles);
    roles.clear();
    roles.addAll(noDupesRoles);
}

This obviously impedes performance, and I was wondering if there's a better way of returning the list with no duplicates.

apines
  • 1,254
  • 14
  • 36

0 Answers0