Affects ORM 6.2, but not 5.6, and (I think) not 6.1 either.
With the following model, attempting to remove one entity from the associations may result in the whole association being cleared.
{code:java} @Entity(name = "containing") public static class ContainingEntity { @Id private Integer id;
@ManyToMany @JoinTable(inverseJoinColumns = @JoinColumn(name = "inverse")) @SortNatural private SortedSet<ContainedEntity> contained = new TreeSet<>();
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
public SortedSet<ContainedEntity> getContained() { return contained; }
public void setContained(SortedSet<ContainedEntity> contained) { this.contained = contained; }
}
@Entity(name = "contained") public static class ContainedEntity implements Comparable<ContainedEntity> {
@Id private Integer id;
@ManyToMany(mappedBy = "contained") private List<ContainingEntity> containing = new ArrayList<>();
@Override public int compareTo(ContainedEntity o) { return getId() - o.getId(); }
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
public List<ContainingEntity> getContaining() { return containing; }
}{code}
The problem appears to be in the SQL generated to clear remove an element from the association, which completely ignores one side of the association:
{noformat}13:52:57,376 DEBUG SQL:128 - delete from containing_contained where containing_id=?{noformat}
Whereas, when {{@JoinTable(inverseColumn)}} is not used, we get:
{noformat}13:57:51,481 DEBUG SQL:128 - delete from containing_contained where containing_id=? and contained_id=?{noformat}
Removing {{@JoinTable(inverseColumn = ...)}}, or moving from {{SortedSet}} to {{List}}, makes the problem disappear.
I will submit a reproducer in the comments. |
|