Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6606627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:24:58+00:00 2026-05-25T19:24:58+00:00

I am getting an odd bug when I am removing an entity using the

  • 0

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 I have no new entities. I think this may be a bug in Doctrine but figured I would ask around a bit first to make sure that I wasn’t doing anything wrong before filling a report.

The relevant code:

<?php
$em = Doctrine\ORM\EntityManager::create(array('driver' => 'pdo_sqlite', 'memory' => true), $config);

$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();
});

If I remove the $em->transactional that wraps the remove and flush operation the remove works. Also, if I remove $qb->getQuery()->getResult(); for the previous query the remove and flush call works.

The error I am getting is:

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 complete working example can be found in this gist.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:24:58+00:00Added an answer on May 25, 2026 at 7:24 pm

    I figured this out eventually after filling a bug report.

    transactional does a flush internally and the double flush was creating this issue. I don’t think a double flush should break things but I didn’t argue that point.

    With that said I wasn’t using transactional correctly, Doctrine 2 has implicit transactions and there is no need to wrap database calls in transactional except under very specific instances.

    From the Doctrine 2 documentation

    Explicit transaction demarcation is required when you want to include custom DBAL operations in a unit of work or when you want to make use of some methods of the EntityManager API that require an active transaction. Such methods will throw a TransactionRequiredException to inform you of that requirement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting an odd result when serializing a DateTime field using XmlSerializer. I have
I'm using a double-linked list and getting some odd performance regarding edge cases when
I am getting an odd intermittent bug that seems to ve related to the
I'm getting an odd error when I try to push to a new remote
I'm getting an odd exception when running my java web project. It seems like
I'm using Compact Framework 3.5 / VS2008. I'm getting really odd behavior with TypeLoadException.
Running a Java Swing program on Ubuntu Linux, I'm getting an odd bug where
I've been getting some odd behavior using a foreach today. I have a dataset
I am getting an odd error when running $dom = new DOMDocument(1.0, utf-8);: Warning
I’m getting some odd results with my tests. I’m using a dual monitor setup

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.