A general suggestion with m-n relations is to use Set instead of List because it offers better performance for certain operations.
I'm trying to combine this with the annotation @OrderColumn(name = "position"). I use this so I don't need a "join table class". I want Hibernate to set the position value according to the position of the element in the set. Therefore I use a LinkedHashSet.
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
@JoinTable(name = "bundle_group_to_bundle", joinColumns = @JoinColumn(name = "fk_bundle_group"), inverseJoinColumns = @JoinColumn(name = "fk_bundle"))
@OrderColumn(name = "position", nullable = false)
private Set<Bundle> bundles = new LinkedHashSet<>();
I can't get this to work. Hibernate ignores the position attribute completely when reading or writing entities. As soon as I replace this with List it works fine.
Does Hibernate support @OrderColumn with Set?
Note: I tried using SortedSet instead of Set but that requires either @Sort (deprecated) or @OrderBy (cannot be used with @OrderColumn) which I can't use in my case.