Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDC-1138: Remove Entity and Transactional #1737

Closed
doctrinebot opened this issue May 6, 2011 · 5 comments
Closed

DDC-1138: Remove Entity and Transactional #1737

doctrinebot opened this issue May 6, 2011 · 5 comments
Assignees
Labels

Comments

@doctrinebot
Copy link

Jira issue originally created by user mitmaro:

I am getting an odd bug when I am removing an entity using the entity manager. An exception is being thrown saying "A new entity was found through a relationship that was not configured to cascade persist operations" but there are no new entities explicitly created.

This is the relevant piece of code and I have attached a full reduced test case.

$qb = $em
    ->getRepository('Bar')
    ->createQueryBuilder('bar1')
    ->select('bar1, foo1, bar2')
    ->join('bar1.foo', 'foo1')
    ->join('foo1.bar', 'bar2')
;

$qb->getQuery()->getResult();

$bar = $em->getRepository('Bar')->findOneBy(array('id' => 20));

$em->transactional(function($em) use ($bar) {
    $em->remove($bar);
    $em->flush();
});

Exception:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'A new entity was found through a relationship
that was not configured to cascade persist operations: Bar@0000000049dcca970000000025d8d6f9. Explicitly persist
the new entity or configure cascading persist operations on the relationship.' in doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php:576
Stack trace:
  #0 doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php(495): Doctrine\ORM\UnitOfWork >computeAssociationChanges(Array, Object(Doctrine\ORM\PersistentCollection))
  #1 doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php(537): Doctrine\ORM\UnitOfWork->computeChangeSet(Object(Doctrine\ORM\Mapping\ClassMetadata), Object(Foo))
  #2 doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php(256): Doctrine\ORM\UnitOfWork->computeChangeSets()
  #3 doctrine2-orm/lib/Doctrine/ORM/EntityManager.php(334): Doctrine\ORM\UnitO in doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php on line 576

A few other things I have noticed:

  • Removing the transactional wrapper and using the DBAL connection transaction fixes the problem
  • Removing the query before the update fixes the problem.
  • The remove works without using an explicit transaction
@doctrinebot
Copy link
Author

Comment created by mitmaro:

Uploaded the wrong test file.

@doctrinebot
Copy link
Author

Comment created by @beberlei:

transactional() calls flush for you. You don't have to do it yourself.

Your code probably fails because of this double flush, can you verify?

@doctrinebot
Copy link
Author

Issue was closed with resolution "Invalid"

@doctrinebot
Copy link
Author

Comment created by mitmaro:

Verified. That does seem to be the issue. Thanks.

@doctrinebot
Copy link
Author

Imported 2 attachments from Jira into https://gist.github.com/b8de79dc495a9035ce52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants