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

Merged entity fields are inconsistent in listeners

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects versions: 5.2.6
    • Fix versions: None
    • Components: hibernate-core
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

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

      Description

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

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

      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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              heruan Giovanni Lovato
              Participants:
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: