OpenJPA
  1. OpenJPA
  2. OPENJPA-1644

Null field values after calling EntityManager.remove()

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.2, 2.0.0
    • Fix Version/s: 1.2.3, 2.1.0
    • Component/s: None
    • Labels:
      None

      Description

      Fields of an entity instance are nulled after calling EntityManager.remove() on an instance.

      For example, I have an entity class named User. I persist and then remove an instance of User.

      //
      // EntityManager em is initialized before the following code
      //

      em.getTransaction().begin();
      User user = new User();
      user.setName("name1");
      em.persist(user);
      em.getTransaction().commit();
      System.out.println(user.getName); // will print out name1
      em.getTransaction().begin();
      em.remove(user);
      em.getTransaction().commit();
      System.out.println(user.getName); // will print out null (oh no!)

      After I persist and remove the same instance of User, it's fields became null. I believe this shouldn't be the case as Section "3.2.3 Removal" of the 2.0 spec states:

      "After an entity has been removed, its state (except for generated state) will be that of the entity at the point at which the remove operation was called."

        Activity

        Leo Isiah Sambayan created issue -
        Rick Curtis made changes -
        Field Original Value New Value
        Affects Version/s 2.0.0 [ 12314019 ]
        Affects Version/s 1.2.2 [ 12313681 ]
        Hide
        Rick Curtis added a comment -

        This patch fixes the reported behavior, but I'm not sure what all it will break(Although all current unit tests pass).

        I need to do some more testing before it is committed.

        Show
        Rick Curtis added a comment - This patch fixes the reported behavior, but I'm not sure what all it will break(Although all current unit tests pass). I need to do some more testing before it is committed.
        Rick Curtis made changes -
        Attachment OPENJPA-1644.patch [ 12443395 ]
        Rick Curtis made changes -
        Assignee Rick Curtis [ curtisr7 ]
        Hide
        Rick Curtis added a comment -

        I did some research as to why we were clearing out the fields of an Entity after deleting it and it appears that it is something that has been with us from the JDO days. Per the JDO spec:

        "A persistent-deleted instance transitions to transient at commit. During the transition, its persistent fields are written with their Java default values...."The net of that is that after an instance is deleted, the provider must clear out all fields of that Entity.

        The JPA 2.0 spec states something along these lines : "After an entity has been removed, its state (except for generated state) will be that of the entity at the point at which the remove operation was called." I'll be committing changes shortly to support the JPA spec.

        Show
        Rick Curtis added a comment - I did some research as to why we were clearing out the fields of an Entity after deleting it and it appears that it is something that has been with us from the JDO days. Per the JDO spec: "A persistent-deleted instance transitions to transient at commit. During the transition, its persistent fields are written with their Java default values...."The net of that is that after an instance is deleted, the provider must clear out all fields of that Entity. The JPA 2.0 spec states something along these lines : "After an entity has been removed, its state (except for generated state) will be that of the entity at the point at which the remove operation was called." I'll be committing changes shortly to support the JPA spec.
        Rick Curtis made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.1.0 [ 12314542 ]
        Resolution Fixed [ 1 ]
        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.
        Michael Dick made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Jeremy Bauer made changes -
        Resolution Fixed [ 1 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Jeremy Bauer made changes -
        Fix Version/s 1.2.3 [ 12314517 ]
        Jeremy Bauer made changes -
        Status Reopened [ 4 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        164d 5h 17m 1 Rick Curtis 11/Oct/10 17:05
        Resolved Resolved Closed Closed
        94d 39m 1 Michael Dick 13/Jan/11 16:45
        Closed Closed Reopened Reopened
        818d 4h 26m 1 Jeremy Bauer 10/Apr/13 22:12
        Reopened Reopened Closed Closed
        24s 1 Jeremy Bauer 10/Apr/13 22:12

          People

          • Assignee:
            Rick Curtis
            Reporter:
            Leo Isiah Sambayan
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development