Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.1
    • Fix Version/s: 2.1.0
    • Component/s: jdbc
    • Labels:
      None

      Description

      I have an entity with a map element collection where the map value is an Embeddable.

      @Embeddable
      public class LocalizedString

      { private String language; private String string; // getters and setters omitted }

      @Entity
      public class MultilingualString

      { @Id private long id; @ElementCollection(fetch=FetchType.EAGER) private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>(); }

      Given a persistent instance m of my entity, I update a member of a given map value and then merge the modified entity:

      EntityManager em = ...;
      em.getTransaction().begin();
      m.getMap().get("en").setString("foo");
      em.merge(m)
      em.getTransaction().commit();

      The problem is, the state change of the map does not get saved to the database. With DEBUG logging on, I can see that the flush on commit does not trigger any SQL UPDATE.

      To force the update, I have to put a new value into the map instead of just changing the existing one.

      EntityManager em = ...;
      em.getTransaction().begin();
      m.getMap().put("en"), new LocalizedString("en", "foo"));
      em.merge(m)
      em.getTransaction().commit();

      After this change, I do see the expected UPDATE.

      My Embeddable does have hashCode() and equals() implemented such that the changed map is not equal() to the former version in either case.

      This looks like a bug in the dirty-checking logic in OpenJPA.

      1. OPENJPA-1784.patch
        12 kB
        Fay Wang
      2. MapUpdate.patch
        9 kB
        Harald Wellmann

        Activity

        Hide
        Harald Wellmann added a comment - - edited

        The attachment MapUpdate.patch contains a unit test exhibiting the problem. A test which updates a map key passes. Another test which only update the map value fails.

        Show
        Harald Wellmann added a comment - - edited The attachment MapUpdate.patch contains a unit test exhibiting the problem. A test which updates a map key passes. Another test which only update the map value fails.
        Hide
        Fay Wang added a comment -

        Change in persistent map are detected by OpenJPA when the the put/remove method is called. In the example, the get method is called to retrieve the value. Currently there is no way for the persistent map to know whether the value is modified or not. A new mechanism needs to be added to detect the change.

        Show
        Fay Wang added a comment - Change in persistent map are detected by OpenJPA when the the put/remove method is called. In the example, the get method is called to retrieve the value. Currently there is no way for the persistent map to know whether the value is modified or not. A new mechanism needs to be added to detect the change.
        Hide
        Michael Dick added a comment -

        Closing issue which has been resolved for some time. If you believe the issue is not resolved please reopen or open a new issue.

        Show
        Michael Dick added a comment - Closing issue which has been resolved for some time. If you believe the issue is not resolved please reopen or open a new issue.

          People

          • Assignee:
            Fay Wang
            Reporter:
            Harald Wellmann
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development