glassfish
  1. glassfish
  2. GLASSFISH-2894

merge does not trigger prepersist callbacks

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 9.0pe
    • Fix Version/s: 9.1pe_dev
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      2,894

      Description

      Calling em.merge(entity) on a new entity does not trigger prepersist callbacks,
      though em.persist does. For instance:

      SportsCar sportsCar = new SportsCar();
      sportsCar.setPassengerCapacity(new Integer(2));
      sportsCar.setFuelCapacity(new Integer(90));
      sportsCar.setDescription("Viper");
      sportsCar.setFuelType("Gas");
      em.persist(sportsCar);
      em.getTransaction().commit();

      Does trigger the prepersist on sportsCar, but :

      SportsCar sportsCar = new SportsCar();
      sportsCar.setPassengerCapacity(new Integer(2));
      sportsCar.setFuelCapacity(new Integer(90));
      sportsCar.setDescription("Viper");
      sportsCar.setFuelType("Gas");
      em.merge(sportsCar);
      em.getTransaction().commit();

      does not.

        Activity

        Hide
        mb124283 added a comment -
            • Issue 3002 has been marked as a duplicate of this issue. ***
        Show
        mb124283 added a comment - Issue 3002 has been marked as a duplicate of this issue. ***
        Hide
        mb124283 added a comment -

        Issue 3002 describes the same problem in a different scenario: a new instance is
        added as a relationship (annotated as cascade ALL) a persistent instance. Then
        merge on the persistent instance does not trigger the prepersist callback. I
        attach a simple JavaSE test case to reproduce the issue.

        I upgrade the priority to P3, since there are more scenarios and the workaround
        explicitly calling em.persist is ugly.

        Show
        mb124283 added a comment - Issue 3002 describes the same problem in a different scenario: a new instance is added as a relationship (annotated as cascade ALL) a persistent instance. Then merge on the persistent instance does not trigger the prepersist callback. I attach a simple JavaSE test case to reproduce the issue. I upgrade the priority to P3, since there are more scenarios and the workaround explicitly calling em.persist is ugly.
        Hide
        mb124283 added a comment -

        Created an attachment (id=913)
        Test case to reproduce the issue.

        Show
        mb124283 added a comment - Created an attachment (id=913) Test case to reproduce the issue.
        Hide
        mf125085 added a comment -

        taking over

        Show
        mf125085 added a comment - taking over
        Hide
        mf125085 added a comment -

        starting

        Show
        mf125085 added a comment - starting
        Hide
        mf125085 added a comment -

        Fixed by moving prePersist callback execution from
        UoW.registerNotRegisteredNewObjectForPersist(Object, ClassDescriptor) to
        UoW.registerNewObjectClone(Object, Object, ClassDescriptor)
        which is called for all new instances when registering instance in UoW.

        Show
        mf125085 added a comment - Fixed by moving prePersist callback execution from UoW.registerNotRegisteredNewObjectForPersist(Object, ClassDescriptor) to UoW.registerNewObjectClone(Object, Object, ClassDescriptor) which is called for all new instances when registering instance in UoW.
        Show
        mf125085 added a comment - Link to changes: http://fisheye5.cenqua.com/changelog/glassfish/?cs=MAIN:mf125085:20070605192351

          People

          • Assignee:
            mf125085
            Reporter:
            chris_delahunt
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: