Merging List ElementCollection PK Violation

Hello Hibernate experts,

I have an Entity with the following ElementCollection:

@ElementCollection(fetch = FetchType.EAGER)
    name = "MY_STRINGS",
    joinColumns = @JoinColumn(
        name = "STRINGLIST_OID",
        foreignKey = @ForeignKey(name = "FK_STRING_TO_PARENT")))
@OrderColumn(name = "STRING_POSITION")
private List<String> myStrings;
  • Create a new instance and persist it.
  • Load instance and assign detached to variable instance1
  • Load instance and assign detached to variable instance2
  • Add “foo” to instance1
  • Merge instance1
  • Add “bar” to instance2
  • Merge instance2

The result is a PK violation, because a new insert statement is created for the first list position.

Is this the expected behavior?

I noticed that there is some piece of code that explicitly restores the old snapshot (in my example the empty list for instance2) before generating the database statements, although the bean already knows better, i.e. it has the current database snapshot available (CollectionEntry.resetStoredSnapshot). Is this intentional?

Is there a recommended way to circumvent this problem?

Thank you very much in advance! Best regards,