This appears to be a bug but I want to be sure I am not doing something incorrect. I have the following class relationships:
@Embeddable
public class EmbeddableData implements Serializable {
@Column(name = "DATA_X", nullable = false)
private double x;
@Column(name = "DATA_Y", nullable = false)
private double y;
...
}
@Entity
public class EntityA implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private long id;
@CollectionTable(name = "DATA_TABLE", joinColumns = @JoinColumn(name = "ENTITY_FK", nullable = false))
@ElementCollection
@OrderColumn(name = "ARRAY_INDEX", nullable = false)
private List<EmbeddableData> data;
...
}
So I persist an instance of EntityA with 4 EmbeddableData instances in the data list which works as expected. Then I change one instance in the list keeping just 4 items and do a merge. However, instead of deleting the old item for the index I changed and then inserting the new item for that index, a new item is inserted which leaves 5 items in the database (2 with the same ARRAY_INDEX). Why is that the case?