Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-824

EntityManager::remove($entity), EntityManager::flush() does not remove the entity from DB

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: 2.0-RC1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      PgSQL 8.4, current Doctrine 2 from Git

      Description

      Test.php
      /* 
       * @Entity
       * @Table(indexes={@Index(name="name", columns={"name"})})
       */
      class ProductAttribute
      {
      
          /**
           * ID
           * 
           * @Id @Column(type="integer") @GeneratedValue
           *
           * @var integer
           */
          protected $id;
          /**
           * Name
           *
           * @Column
           *
           * @var string
           */
          protected $name;
          /**
           * Values
           *
           * @OneToMany(targetEntity="ProductAttributeValue", mappedBy="attribute")
           *
           * @var array
           */
          protected $values;
      
          /**
           * Gets ID
           *
           * @return integer ID
           */
          public function getId()
          {
              return $this->id;
          }
      
          /**
           * Sets ID
           *
           * @param integer $id ID
           *
           * @return void
           */
          public function setId($id = null)
          {
              $this->id = $id;
          }
      
          /**
           * Gets name
           *
           * @return string Name
           */
          public function getName()
          {
              return $this->name;
          }
      
          /**
           * Sets name
           *
           * @param string $name Name
           *
           * @return void
           */
          public function setName($name = null)
          {
              $this->name = $name;
          }
      
          /**
           * Gets product attribute values
           *
           * @return array Product attribute values
           */
          public function getValues()
          {
              return $this->values;
          }
      
          /**
           * Adds product attribute value
           *
           * @param ProductAttributeValue $value Product attribute value
           * 
           * @return void
           */
          public function addValue(ProductAttributeValue $value)
          {
              $value->setAttribute($this);
              $this->values[] = $value;
          }
      
      }
      
      $attribute = $em->find('ProductAttribute', 1);
      $em->remove($attribute);
      $em->flush();
      

      The upper code won't remove the entity from the database.... Corresponding DQL (DELETE ProductAttribute a WHERE a.id = 1) will remove it from the database...

        Activity

        Petr Motejlek created issue -
        Petr Motejlek made changes -
        Field Original Value New Value
        Description /*
         * @Entity
         * @Table(indexes={@Index(name="name", columns={"name"})})
         */
        class ProductAttribute
        {

            /**
             * ID
             *
             * @Id @Column(type="integer") @GeneratedValue
             *
             * @var integer
             */
            protected $id;
            /**
             * Name
             *
             * @Column
             *
             * @var string
             */
            protected $name;
            /**
             * Values
             *
             * @OneToMany(targetEntity="ProductAttributeValue", mappedBy="attribute")
             *
             * @var array
             */
            protected $values;

            /**
             * Gets ID
             *
             * @return integer ID
             */
            public function getId()
            {
                return $this->id;
            }

            /**
             * Sets ID
             *
             * @param integer $id ID
             *
             * @return void
             */
            public function setId($id = null)
            {
                $this->id = $id;
            }

            /**
             * Gets name
             *
             * @return string Name
             */
            public function getName()
            {
                return $this->name;
            }

            /**
             * Sets name
             *
             * @param string $name Name
             *
             * @return void
             */
            public function setName($name = null)
            {
                $this->name = $name;
            }

            /**
             * Gets product attribute values
             *
             * @return array Product attribute values
             */
            public function getValues()
            {
                return $this->values;
            }

            /**
             * Adds product attribute value
             *
             * @param ProductAttributeValue $value Product attribute value
             *
             * @return void
             */
            public function addValue(ProductAttributeValue $value)
            {
                $value->setAttribute($this);
                $this->values[] = $value;
            }

        }

        $attribute = $em->find('ProductAttribute', 1);
        $em->remove($attribute);
        $em->flush();

        The upper code won't remove the entity from the database.... Corresponding DQL (DELETE ProductAttribute a WHERE a.id = 1) will remove it from the database...
        {code:title=Test.php|borderStyle=solid}
        /*
         * @Entity
         * @Table(indexes={@Index(name="name", columns={"name"})})
         */
        class ProductAttribute
        {

            /**
             * ID
             *
             * @Id @Column(type="integer") @GeneratedValue
             *
             * @var integer
             */
            protected $id;
            /**
             * Name
             *
             * @Column
             *
             * @var string
             */
            protected $name;
            /**
             * Values
             *
             * @OneToMany(targetEntity="ProductAttributeValue", mappedBy="attribute")
             *
             * @var array
             */
            protected $values;

            /**
             * Gets ID
             *
             * @return integer ID
             */
            public function getId()
            {
                return $this->id;
            }

            /**
             * Sets ID
             *
             * @param integer $id ID
             *
             * @return void
             */
            public function setId($id = null)
            {
                $this->id = $id;
            }

            /**
             * Gets name
             *
             * @return string Name
             */
            public function getName()
            {
                return $this->name;
            }

            /**
             * Sets name
             *
             * @param string $name Name
             *
             * @return void
             */
            public function setName($name = null)
            {
                $this->name = $name;
            }

            /**
             * Gets product attribute values
             *
             * @return array Product attribute values
             */
            public function getValues()
            {
                return $this->values;
            }

            /**
             * Adds product attribute value
             *
             * @param ProductAttributeValue $value Product attribute value
             *
             * @return void
             */
            public function addValue(ProductAttributeValue $value)
            {
                $value->setAttribute($this);
                $this->values[] = $value;
            }

        }

        $attribute = $em->find('ProductAttribute', 1);
        $em->remove($attribute);
        $em->flush();
        {code}

        The upper code won't remove the entity from the database.... Corresponding DQL (DELETE ProductAttribute a WHERE a.id = 1) will remove it from the database...
        Hide
        Petr Motejlek added a comment -

        I just found out, that when I have an entity containing a *ToMany column with cascade=

        {"remove"}

        set, all the entities are removed, except for the one...

        Show
        Petr Motejlek added a comment - I just found out, that when I have an entity containing a *ToMany column with cascade= {"remove"} set, all the entities are removed, except for the one...
        Roman S. Borschel made changes -
        Assignee Roman S. Borschel [ romanb ] Benjamin Eberlei [ beberlei ]
        Roman S. Borschel made changes -
        Fix Version/s 2.0-RC1 [ 10091 ]
        Hide
        Benjamin Eberlei added a comment -

        I cannot reproduce this issue. Can you try to build a reproducible test-case? Have a look at tests/Doctrine/Tests/ORM/Functional/Ticket/* and build a test-case like this one here:

        <?php
        
        namespace Doctrine\Tests\ORM\Functional\Ticket;
        
        use Doctrine\Common\Collections\ArrayCollection;
        use Doctrine\Tests\Models\CMS\CmsUser;
        use Doctrine\Tests\Models\CMS\CmsGroup;
        
        require_once __DIR__ . '/../../../TestInit.php';
        
        class DDC824Test extends \Doctrine\Tests\OrmFunctionalTestCase
        {
            public function setUp()
            {
                $this->useModelSet('cms');
                parent::setUp();
            }
        
            public function testRemoveWithCascade()
            {
                $user = new CmsUser();
                $user->username = "beberlei";
                $user->name = "Benjamin";
                $user->status = "active";
        
                $phone1 = new \Doctrine\Tests\Models\CMS\CmsPhonenumber();
                $phone1->phonenumber = "1234";
                $phone2 = new \Doctrine\Tests\Models\CMS\CmsPhonenumber();
                $phone2->phonenumber = "1235";
        
                $user->addPhonenumber($phone1);
                $user->addPhonenumber($phone2);
        
                $this->_em->persist($user);
                $this->_em->flush();
                $this->_em->clear();
        
                $user = $this->_em->find(get_class($user), $user->id);
                $phone1 = $user->phonenumbers[0];
                $phone2 = $user->phonenumbers[1];
        
                $this->assertTrue($this->_em->contains($user));
                $this->assertTrue($this->_em->contains($phone1));
                $this->assertTrue($this->_em->contains($phone2));
        
                $this->_em->remove($user);
        
                $this->assertFalse($this->_em->contains($user));
                $this->assertFalse($this->_em->contains($phone1));
                $this->assertFalse($this->_em->contains($phone2));
            }
        }
        
        Show
        Benjamin Eberlei added a comment - I cannot reproduce this issue. Can you try to build a reproducible test-case? Have a look at tests/Doctrine/Tests/ORM/Functional/Ticket/* and build a test-case like this one here: <?php namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsGroup; require_once __DIR__ . '/../../../TestInit.php'; class DDC824Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function setUp() { $ this ->useModelSet('cms'); parent::setUp(); } public function testRemoveWithCascade() { $user = new CmsUser(); $user->username = "beberlei" ; $user->name = "Benjamin" ; $user->status = "active" ; $phone1 = new \Doctrine\Tests\Models\CMS\CmsPhonenumber(); $phone1->phonenumber = "1234" ; $phone2 = new \Doctrine\Tests\Models\CMS\CmsPhonenumber(); $phone2->phonenumber = "1235" ; $user->addPhonenumber($phone1); $user->addPhonenumber($phone2); $ this ->_em->persist($user); $ this ->_em->flush(); $ this ->_em->clear(); $user = $ this ->_em->find(get_class($user), $user->id); $phone1 = $user->phonenumbers[0]; $phone2 = $user->phonenumbers[1]; $ this ->assertTrue($ this ->_em->contains($user)); $ this ->assertTrue($ this ->_em->contains($phone1)); $ this ->assertTrue($ this ->_em->contains($phone2)); $ this ->_em->remove($user); $ this ->assertFalse($ this ->_em->contains($user)); $ this ->assertFalse($ this ->_em->contains($phone1)); $ this ->assertFalse($ this ->_em->contains($phone2)); } }
        Hide
        Petr Motejlek added a comment -

        I found out that I cannot reproduce the same behaviour with different project of mine either. It seems there's simply something rotten inside the one. I'll try investigating it a bit farther, but I think you can close this issue for now. Thanks for your time .

        Show
        Petr Motejlek added a comment - I found out that I cannot reproduce the same behaviour with different project of mine either. It seems there's simply something rotten inside the one. I'll try investigating it a bit farther, but I think you can close this issue for now. Thanks for your time .
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 11975 ] jira-feedback [ 14595 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 14595 ] jira-feedback2 [ 16459 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16459 ] jira-feedback3 [ 18712 ]

        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-824, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Petr Motejlek
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: