Eclipselink JPA - Update entity with @EmbeddedCollection and map does not insert new entry
<p>I am looking at a very simple entity with a <code>Map</code> <code>@ElementCollection</code>.</p>

<p>The entity:</p>

<pre><code>@Entity
@RequiredArgsConstructor @NoArgsConstructor @Data
public class Attribute {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NonNull
    private String name;

    @ElementCollection
    private Map&lt;Integer, AttributeValue&gt; attributes = new HashMap&lt;&gt;();
}
</code></pre>

<p>The <code>Embeddable</code> used as the map value:</p>

<pre><code>@Embeddable
@RequiredArgsConstructor @NoArgsConstructor(access = PRIVATE) @Data
public class AttributeValue {

    @NonNull
    private String name;
}
</code></pre>

<p>When I try to update the entity with a new map entry where there is already an equal persisted value (with the same <code>name</code> in this case) the map entry is not inserted.</p>

<p>This test reproduces this issue:</p>

<pre><code>@Test
    public void should_persist_attribute_with_same_value() {
        Attribute name = new Attribute("name");

        name.getAttributes().put(1, new AttributeValue("1"));
        name.getAttributes().put(2, new AttributeValue("2"));

        name = attributeRepository.saveAndFlush(name);

        name.getAttributes().put(3, new AttributeValue("2")); //this value is already in the map and is not inserted
        name.getAttributes().put(4, new AttributeValue("4"));

        name = attributeRepository.saveAndFlush(name);

        entityManager.clear();
        //the assertion fails and finds only three items (with key 1,2 and 4)
        then(attributeRepository.findOne(name.getId()).getAttributes()).hasSize(4);
    }
</code></pre>

<p>It seems that there is a bug in eclipselink that ignores map values that are already used with another map key in the map. </p>

<p>I also tried with hibernate - there the same code works as expected.</p>

<p>Any ideas?</p>

<p>I am using:</p>

<ul>
<li>spring-boot 1-4-0.M2</li>
<li>spring-data-jpa 1.10.1.RELEASE</li>
<li>eclipselink 2.6.1</li>
</ul>