DDC-406: A detached entity can not be removed, on @OneToOne cascade={"remove"} #4895

Closed
doctrinebot opened this Issue Mar 11, 2010 · 11 comments

1 participant

@doctrinebot

Jira issue originally created by user else:

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

@doctrinebot

Comment created by else:

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

@doctrinebot

Comment created by romanb:

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".

@doctrinebot

Comment created by else:

Dear Roman,
Check this issue at first: http://www.doctrine-project.org/jira/browse/[DDC-422](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

@doctrinebot

Comment created by else:

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

@doctrinebot

Comment created by romanb:

@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.

@doctrinebot

Comment created by romanb:

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

@doctrinebot

Comment created by romanb:

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

@doctrinebot

Comment created by else:

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

@doctrinebot

Comment created by romanb:

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

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-BETA1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment