| My test case is here: https://github.com/moodysalem/hibernate-tests/blob/master/src/test/java/Tests.java#L50 I have a competition with this map of an embeddable entity
@MapKeyColumn(name = "side")
@MapKeyEnumerated(EnumType.STRING)
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
name = "competition_participants",
joinColumns = @JoinColumn(name = "competition_id", nullable = false),
uniqueConstraints = {@UniqueConstraint(columnNames = {"competition_id", "side"})}
)
private Map<Side, Participant> participants;
Here is the embedded entity
public class Participant {
public Participant(String name, Integer number) {
this.name = name;
this.number = number;
}
public Participant() {
}
@Basic
private String name;
@Basic
private Integer number;
}
I don't care whether the fetch from the database represents an empty Participant as NULL or an object with null values, but when later saving changes to this entity, if there is a unique constraint on Side and Competition ID (one participant per side), we get an error because the generated SQL attempts to insert for that side rather than UPDATE. |