OpenJPA
  1. OpenJPA
  2. OPENJPA-984

PostLoad and PostUpdate not called for objects with a bidirectional relationship

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.1, 1.3.0
    • Fix Version/s: None
    • Component/s: jdbc
    • Labels:
      None

      Description

      A method marked with @PostLoad or @PostUpdate on an object that is the toMany side of a bi-directional relationship does not get called when the other object is loaded or updated.

      I can confirm that this problem was introduced by the changes done in OPENJPA-744. Looks like the StateManagerImpl.postLoad() method is not firing the event due to the bidirectional field not being flagged as loaded.

      An example:

      @Entity
      public class Order {
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "order", fetch = FetchType.EAGER)
      public List<Shipment> getShipments()

      { return shipments; }

      }

      @Entity
      public class Shipment {
      @ManyToOne(fetch = FetchType.EAGER, cascade =

      { CascadeType.MERGE, CascadeType.REFRESH }

      )
      public Order getOrder()

      { return order; }

      @PostLoad
      public void doSomethingAfterLoad()

      { // do something }

      }

      In the above example the doSomethingAfterLoad() never gets called when you load an Order. Without the changes done in OPENJPA-744 it does.

        Activity

        Simon Droscher created issue -
        Simon Droscher made changes -
        Field Original Value New Value
        Description A method marked with @PostLoad or @PostUpdate on an object that is the toMany side of a bi-directional relationship does not get called when the other object is loaded or updated.

        I can confirm that this problem was introduced by the changes done in [OPENJPA-744]. Looks like the StateManagerImpl.postLoad() method is not firing the event due to the bidirectional field not being flagged as loaded.

        An example:

        {code}
        @Entity
        public class Order {
          @OneToMany(cascade = CascadeType.ALL, mappedBy = "order", fetch = FetchType.EAGER)
          public List<Shipment> getShipments() {
            return shipments;
          }
        }

        @Entity
        public class Shipment {
          @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.MERGE, CascadeType.REFRESH })
          public Order getOrder() {
            return order;
          }

          @PostLoad
          public void doSomethingAfterLoad() {
            // do something
          }
        }
        {code}

        In the above example the doSomethingAfterLoad() never gets called when you load an Order. Without the changes done in [OPENJPA-744] it does.
        A method marked with @PostLoad or @PostUpdate on an object that is the toMany side of a bi-directional relationship does not get called when the other object is loaded or updated.

        I can confirm that this problem was introduced by the changes done in [OPENJPA-744]. Looks like the StateManagerImpl.postLoad() method is not firing the event due to the bidirectional field not being flagged as loaded.

        An example:

        @Entity
        public class Order {
          @OneToMany(cascade = CascadeType.ALL, mappedBy = "order", fetch = FetchType.EAGER)
          public List<Shipment> getShipments() {
            return shipments;
          }
        }

        @Entity
        public class Shipment {
          @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.MERGE, CascadeType.REFRESH })
          public Order getOrder() {
            return order;
          }

          @PostLoad
          public void doSomethingAfterLoad() {
            // do something
          }
        }

        In the above example the doSomethingAfterLoad() never gets called when you load an Order. Without the changes done in [OPENJPA-744] it does.

          People

          • Assignee:
            Unassigned
            Reporter:
            Simon Droscher
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development