We're updating the issue view to help you get more done. 

ElementCollection with MapKeyColumn and Embeddable value represents empty rows as null values

Description

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

1 2 3 4 5 6 7 8 9 @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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 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.

Environment

hibernate-core 5.2.5, h2 and mysql

Status

Assignee

Gail Badner

Reporter

Moody Salem

Components

Affects versions

5.2.5

Priority

Major