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

Merged entity fields are inconsistent in listeners

Description

An entity with a `@ElementCollection Map map` when merged lose the map elements in its listeners. For example:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 @Entity @EntityListeners(FooListener.class) public class Foo { @Id private long id; @ElementCollection private Map<String, String> map = new HashMap<>(); // getters and setters } public class FooListener { @PrePersist public void preUpdate(Foo foo) { System.out.println(foo); System.out.println(foo.getMap().size()); } } Foo foo = new Foo(); foo.getMap().put("foo", "test"); System.out.println(foo); System.out.println(foo.getMap().size()); System.out.println("before merge"); Foo merge = entityManager.merge(foo); System.out.println("after merge"); System.out.println(merge); System.out.println(merge.getMap().size());

this will print something like that:

1 2 3 4 5 6 7 8 Foo@3af17be2 1 before merge Foo@285d851a 0 after merge Foo@285d851a 1

where it's clear the instance of `Foo` passed to the listener has an empty map.

Environment

None

Status

Assignee

Unassigned

Reporter

Giovanni Lovato

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.6

Priority

Major