Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2157

@HasLifecycleCallbacks does not fire events when set on @MappedSuperclass

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Invalid
    • Affects Version/s: 2.2.3
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Environment:
      Windows 7 x64 / Apache 2.4.2 / MySQL server 5.1.62

      Description

      I am unable to fire any of the "HasLifecycleCallbacks" when defined on a MappedSuperclass... (neither PreUpdate, PostUpdate,PrePersist, PostPersist and others)

      I have even tried to put @ORM\HasLifecycleCallbacks on the child class with onPostRemove() on mapped => not working anymore

      It only works when i put @ORM\HasLifecycleCallbacks and onPostRemove() both in child class "MyMappedTask"...

      Is this a bug ..?

      To reproduce :

      <?php
      namespace MyProject\Entity;
      
      use Doctrine\ORM\Mapping as ORM;
      
      /**
       * @ORM\MappedSuperclass
       * @ORM\HasLifecycleCallbacks
       */
      class MyMappedTask
      {
         /**
          * @ORM\PreRemove
          * @ORM\PostRemove
          * @ORM\PreUpdate
          * @ORM\PostUpdate
           */
          public function onPostRemove()
          {
              echo "here is never reached !";
          }
      }
      
      /**
       * @ORM\Entity(repositoryClass="MyProject\Repository\MyTaskRepository")
       * @ORM\Table()
       */
      class MyTask extends MyMappedTask
      {
      
      }
      

        Activity

        Frederic created issue -
        Frederic made changes -
        Field Original Value New Value
        Labels HasLifecycleCallbacks MappedSuperclass
        Hide
        Fabio B. Silva added a comment -

        code format

        Show
        Fabio B. Silva added a comment - code format
        Fabio B. Silva made changes -
        Description I am unable to fire any of the "HasLifecycleCallbacks" when defined on a MappedSuperclass...

        I have even tried to put @ORM\HasLifecycleCallbacks on the child class with onPostRemove() on mapped => not working anymore

        It only works when i put @ORM\HasLifecycleCallbacks and onPostRemove() both in child class "MyMappedTask"...

        Is this a bug ..?

        To reproduce :

        <?php
        namespace MyProject\Entity;

        use Doctrine\ORM\Mapping as ORM;

        /**
         * @ORM\MappedSuperclass
         * @ORM\HasLifecycleCallbacks
         */
        class MyMappedTask
        {
        /**
             * @ORM\PostRemove
             */
            public function onPostRemove()
            {
                echo "in onPostRemove";
            }
        }

        /**
         * @ORM\Entity(repositoryClass="MyProject\Repository\MyTaskRepository")
         * @ORM\Table()
         */
        class MyTask extends MyMappedTask
        {

        }
        I am unable to fire any of the "HasLifecycleCallbacks" when defined on a MappedSuperclass...

        I have even tried to put @ORM\HasLifecycleCallbacks on the child class with onPostRemove() on mapped => not working anymore

        It only works when i put @ORM\HasLifecycleCallbacks and onPostRemove() both in child class "MyMappedTask"...

        Is this a bug ..?

        To reproduce :

        {code}
        <?php
        namespace MyProject\Entity;

        use Doctrine\ORM\Mapping as ORM;

        /**
         * @ORM\MappedSuperclass
         * @ORM\HasLifecycleCallbacks
         */
        class MyMappedTask
        {
        /**
             * @ORM\PostRemove
             */
            public function onPostRemove()
            {
                echo "in onPostRemove";
            }
        }

        /**
         * @ORM\Entity(repositoryClass="MyProject\Repository\MyTaskRepository")
         * @ORM\Table()
         */
        class MyTask extends MyMappedTask
        {

        }
        {code}
        Hide
        Fabio B. Silva added a comment -

        Hi Frederic,

        It failed for all events or just for @PostRemove ?

        Could you try to add a failing test case ?

        Cheers

        Show
        Fabio B. Silva added a comment - Hi Frederic, It failed for all events or just for @PostRemove ? Could you try to add a failing test case ? Cheers
        Frederic made changes -
        Description I am unable to fire any of the "HasLifecycleCallbacks" when defined on a MappedSuperclass...

        I have even tried to put @ORM\HasLifecycleCallbacks on the child class with onPostRemove() on mapped => not working anymore

        It only works when i put @ORM\HasLifecycleCallbacks and onPostRemove() both in child class "MyMappedTask"...

        Is this a bug ..?

        To reproduce :

        {code}
        <?php
        namespace MyProject\Entity;

        use Doctrine\ORM\Mapping as ORM;

        /**
         * @ORM\MappedSuperclass
         * @ORM\HasLifecycleCallbacks
         */
        class MyMappedTask
        {
        /**
             * @ORM\PostRemove
             */
            public function onPostRemove()
            {
                echo "in onPostRemove";
            }
        }

        /**
         * @ORM\Entity(repositoryClass="MyProject\Repository\MyTaskRepository")
         * @ORM\Table()
         */
        class MyTask extends MyMappedTask
        {

        }
        {code}
        I am unable to fire any of the "HasLifecycleCallbacks" when defined on a MappedSuperclass... (neither PreUpdate, PostUpdate,PrePersist, PostPersist and others)

        I have even tried to put @ORM\HasLifecycleCallbacks on the child class with onPostRemove() on mapped => not working anymore

        It only works when i put @ORM\HasLifecycleCallbacks and onPostRemove() both in child class "MyMappedTask"...

        Is this a bug ..?

        To reproduce :

        {code}
        <?php
        namespace MyProject\Entity;

        use Doctrine\ORM\Mapping as ORM;

        /**
         * @ORM\MappedSuperclass
         * @ORM\HasLifecycleCallbacks
         */
        class MyMappedTask
        {
           /**
            * @ORM\PreRemove
            * @ORM\PostRemove
            * @ORM\PreUpdate
            * @ORM\PostUpdate
             */
            public function onPostRemove()
            {
                echo "here is never reached !";
            }
        }

        /**
         * @ORM\Entity(repositoryClass="MyProject\Repository\MyTaskRepository")
         * @ORM\Table()
         */
        class MyTask extends MyMappedTask
        {

        }
        {code}
        Hide
        Frederic added a comment -

        Hi Fabio,

        1) Thank you for the "code" tag, i didn't know to do

        2) Is fails with all the Annotations "Pre/Post*" ...

        Did you try this test case ?

        Thank you

        Show
        Frederic added a comment - Hi Fabio, 1) Thank you for the "code" tag, i didn't know to do 2) Is fails with all the Annotations "Pre/Post*" ... Did you try this test case ? Thank you
        Fabio B. Silva made changes -
        Attachment DDC2157Test.php [ 11354 ]
        Hide
        Fabio B. Silva added a comment -

        Hi Frederic,

        Can't reproduce..
        Could you try to change the attached test case and make it fails ?

        Cheers

        Show
        Fabio B. Silva added a comment - Hi Frederic, Can't reproduce.. Could you try to change the attached test case and make it fails ? Cheers
        Fabio B. Silva made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        Hide
        Frederic added a comment -

        Hi Fabio,

        Thank you for the test case, it is OK !

        I found what the problem was :
        I use Symfony2 and i have one bundle with the @MappedSuperclass entity and its callbacks (@HasLifecycleCallbacks), and another bundle with the child class (@Entity/@Table).
        In that case, you must register the 2 bundles on the mappings (config.yml) otherwise it fails.
        (I only registered the bundle which contains the child class but was not enough for Doctrine to understand...)

        I don't know if it is a bug on Symfony2, not well documented in this case...

        Thank you for all

        Show
        Frederic added a comment - Hi Fabio, Thank you for the test case, it is OK ! I found what the problem was : I use Symfony2 and i have one bundle with the @MappedSuperclass entity and its callbacks (@HasLifecycleCallbacks), and another bundle with the child class (@Entity/@Table). In that case, you must register the 2 bundles on the mappings (config.yml) otherwise it fails. (I only registered the bundle which contains the child class but was not enough for Doctrine to understand...) I don't know if it is a bug on Symfony2, not well documented in this case... Thank you for all
        Benjamin Eberlei made changes -
        Status Awaiting Feedback [ 10000 ] In Progress [ 3 ]
        Benjamin Eberlei made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2157, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Frederic
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: