Entity Manager does not configure persists operation after create it #5328

Open
opened 2026-01-22 15:04:40 +01:00 by admin · 0 comments
Owner

Originally created by @andrescevp on GitHub (Nov 17, 2016).

Originally assigned to: @Ocramius on GitHub.

Hello people.

I have the follow issue:

  • First I check that the entity manager is open
  • if it is not open I log the error and create a new one
  • after this I thry to persist a entuty with cascade persists operations but the new entity manager have not configured this operations.

the code:

/**
     * @return EntityManager
     */
    public function getManager($errorContext = [])
    {
        /** @var EntityManager $manager */
        $manager = $this->doctrine->getManager();

        if (!$manager->isOpen()) {

            $errorContext = array_merge(['stack_trace' => debug_backtrace()], $errorContext);

            $this->logger->error('Manager is not connected to database - Reopening connection', $errorContext);

            $manager = $manager->create(
                $manager->getConnection(),
                $manager->getConfiguration()
            );
        }

        return $manager;
    }

The exception:

A new entity was found through the relationship 'Pet\Food#food' that was not configured to cascade persist operations for entity: Food@000000004aacae7600007fdbf3fa2867. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'Food#__toString()' to get a clue.

Some idea?

Thanks!

Originally created by @andrescevp on GitHub (Nov 17, 2016). Originally assigned to: @Ocramius on GitHub. Hello people. I have the follow issue: - First I check that the entity manager is open - if it is not open I log the error and create a new one - after this I thry to persist a entuty with cascade persists operations but the new entity manager have not configured this operations. the code: ``` /** * @return EntityManager */ public function getManager($errorContext = []) { /** @var EntityManager $manager */ $manager = $this->doctrine->getManager(); if (!$manager->isOpen()) { $errorContext = array_merge(['stack_trace' => debug_backtrace()], $errorContext); $this->logger->error('Manager is not connected to database - Reopening connection', $errorContext); $manager = $manager->create( $manager->getConnection(), $manager->getConfiguration() ); } return $manager; } ``` The exception: ``` A new entity was found through the relationship 'Pet\Food#food' that was not configured to cascade persist operations for entity: Food@000000004aacae7600007fdbf3fa2867. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'Food#__toString()' to get a clue. ``` Some idea? Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5328