Uploaded image for project: 'Hibernate ORM'
  1. HHH-11353

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Rejected
    • Affects Version/s: 5.2.5
    • Fix Version/s: None
    • Component/s: hibernate-core
    • Labels:
      None
    • Environment:
      hibernate-core 5.2.5, h2 and mysql
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      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

          @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.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: