Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-406

A detached entity can not be removed, on @OneToOne cascade={"remove"}

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: 2.0-BETA1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      PHP-5.3.1 on Linux-2.6.32-gentoo-r3-x86_64-Intel-R-_Core-TM-2_Duo_CPU_P9500_@_2.53GHz-with-gentoo-2.0.1

      Description

      Dear developers,

      I have class defined like this:

      /**
       * @Entity
       * @HasLifecycleCallbacks
       */
      class Shop_Data_Entity_Customer extends Shop_Data_Entity_Guest {
          /**
           * @OneToOne(targetEntity="Shop_Data_Entity_Contact", cascade={"remove"})
           * @JoinColumn(name="contact", referencedColumnName="id")
           */
          protected $contact;
      
      }
      

      when i run this:

       
      $q = $em->createQuery("select c from Shop_Data_Entity_Customer c");
      $q->setMaxResults(1);
      $customers = $q->getResult();
      $em->remove($customers[0]);
      $em->flush();
      

      I get "A detached entity can not be removed".

      I don't understand it very well. I need to remove associated entity but it's not done and exception occurs.

      I tried it with (like OneToMany)

       
      /**
           * @ManyToMany(targetEntity="Shop_Data_Entity_Contact", cascade={"persist","remove"} )
           * @JoinTable(name="Shop_Data_Entity_Customer__homes",
           *      joinColumns={@JoinColumn(name="customer_id", referencedColumnName="id", onDelete="cascade" )},
           *      inverseJoinColumns={@JoinColumn(name="contact_id", referencedColumnName="id", onDelete="cascade" )}
           *      )
           */
      public $homes;
      

      and

       
      $q = $em->createQuery("select c from Shop_Data_Entity_Customer c");
      $q->setMaxResults(1);
      $customers = $q->getResult();
      $em->remove($customers[0]->homes[0]);
      $em->flush();
      

      worked without problem like this.

      orphanRemoval set it's not working so.

      Thank for solve and perfect ORM!!!

      Andy

      1. DDC406Test.php
        2 kB
        Ondrej Sibrina
      2. DDC406Test.php
        2 kB
        Roman S. Borschel

        Activity

        Hide
        Ondrej Sibrina added a comment -

        Dear Roman,
        When are you going to release 2.0-BETA1 [ 10030 ]? I ask you because i need this patch now to continue my developing.
        Thank you very much.

        Andy

        Show
        Ondrej Sibrina added a comment - Dear Roman, When are you going to release 2.0-BETA1 [ 10030 ]? I ask you because i need this patch now to continue my developing. Thank you very much. Andy
        Hide
        Roman S. Borschel added a comment -

        Hi,

        I created a test case (attached to this issue) that works well. Can you please modify that test so that it reflects your issue or tell me how to modify it so I can reproduce your problem? Thanks.

        If you have the Doctrine tests checked out you can just copy this file into the tests/Doctrine/Tests/ORM/Functional/Ticket folder and run it with: "phpunit Doctrine/Tests/ORM/Functional/Ticket/DDC406Test".

        Show
        Roman S. Borschel added a comment - Hi, I created a test case (attached to this issue) that works well. Can you please modify that test so that it reflects your issue or tell me how to modify it so I can reproduce your problem? Thanks. If you have the Doctrine tests checked out you can just copy this file into the tests/Doctrine/Tests/ORM/Functional/Ticket folder and run it with: "phpunit Doctrine/Tests/ORM/Functional/Ticket/DDC406Test".
        Hide
        Ondrej Sibrina added a comment -

        Dear Roman,
        Check this issue at first: http://www.doctrine-project.org/jira/browse/DDC-422 Maybe my extending cause also this issue. If you can't reproduce it with my extending write me and i'll try your test.

        Thank you.

        Andy

        Show
        Ondrej Sibrina added a comment - Dear Roman, Check this issue at first: http://www.doctrine-project.org/jira/browse/DDC-422 Maybe my extending cause also this issue. If you can't reproduce it with my extending write me and i'll try your test. Thank you. Andy
        Hide
        Ondrej Sibrina added a comment -

        Dear Roman,
        I can't understand how you could run that test.

        First there wasn't set generatedValue strategy so i added it. It throw very stupid exception. Maybe it will be better to correct this error to understand what's wrong easier.

        PHP Fatal error:  Undefined class constant 'Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' in /home/else/download/doctrine/2.0.0-ALPHA4/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php on line 212
        

        Then there wasn't set Column type so added either.

        Then when i run test with "phpunit Doctrine/Tests/ORM/Functional/Ticket/DDC406Test.php" i got same error i reported.

        I'm attaching edited test.

        Andy

        Show
        Ondrej Sibrina added a comment - Dear Roman, I can't understand how you could run that test. First there wasn't set generatedValue strategy so i added it. It throw very stupid exception. Maybe it will be better to correct this error to understand what's wrong easier. PHP Fatal error: Undefined class constant 'Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' in /home/ else /download/doctrine/2.0.0-ALPHA4/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php on line 212 Then there wasn't set Column type so added either. Then when i run test with "phpunit Doctrine/Tests/ORM/Functional/Ticket/DDC406Test.php" i got same error i reported. I'm attaching edited test. Andy
        Hide
        Roman S. Borschel added a comment - - edited

        @GeneratedValue is the same as @GeneratedValue(strategy="AUTO"), AUTO is the default strategy, at least in trunk, and to run the test, you should check out trunk.

        @Column is the same as @Column(type="string"), string is the default type.

        Show
        Roman S. Borschel added a comment - - edited @GeneratedValue is the same as @GeneratedValue(strategy="AUTO"), AUTO is the default strategy, at least in trunk, and to run the test, you should check out trunk. @Column is the same as @Column(type="string"), string is the default type.
        Hide
        Roman S. Borschel added a comment -

        It makes no sense to test against ALPHA4, please use trunk.

        Show
        Roman S. Borschel added a comment - It makes no sense to test against ALPHA4, please use trunk.
        Hide
        Roman S. Borschel added a comment -

        Your new test still works fine for me, again using trunk. So your problem might be already fixed.

        Show
        Roman S. Borschel added a comment - Your new test still works fine for me, again using trunk . So your problem might be already fixed.
        Hide
        Ondrej Sibrina added a comment -

        Dear Roman,

        I checkouted trunk version and it solves this problem. I'm sorry that i consumed your time with that. I'm not used to solve problems like this. Hope i can help better now to make doctrine more stable.

        Andy

        Show
        Ondrej Sibrina added a comment - Dear Roman, I checkouted trunk version and it solves this problem. I'm sorry that i consumed your time with that. I'm not used to solve problems like this. Hope i can help better now to make doctrine more stable. Andy
        Hide
        Roman S. Borschel added a comment -

        OK, at least now you know already how to deal with test cases

        Show
        Roman S. Borschel added a comment - OK, at least now you know already how to deal with test cases

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Ondrej Sibrina
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: