@Entity
@EntityListeners(FooListener.class)
public class Foo {
@Id
private long id;
@ElementCollection
private Map<String, String> map = new HashMap<>();
}
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());