DDC-363: "Entity must be managed" exception thrown trying to persist a Proxy entity #452

Closed
opened 2026-01-22 12:38:45 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 22, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user rickdt:

Occurs in trunk revision 7203

We have two entity with an empty oneToMany association

Client -> Email

When there is no email, I don't know why, the collection is filled with EmailProxy. (Data come from a query hydrated object)

in UnitOfWork::_computeAssociationChanges I see there is a test for Proxy entity but it does not apply to collection.

private function _computeAssociationChanges($assoc, $value)
    {
      .....

        // Look through the entities, and in any of their associations, for transient
        // enities, recursively. ("Persistence by reachability")
        if ($assoc->isOneToOne()) {
            if ($value instanceof Proxy && ! $value->*_isInitialized_*) {
                return; // Ignore uninitialized proxy objects
            }
            $value = array($value);
        } else if ($value instanceof PersistentCollection) {
            $value = $value->unwrap();
        }

        $targetClass = $this->_em->getClassMetadata($assoc->targetEntityName);
        foreach ($value as $entry) {
           ......
        }
    }

Maybe you could try to check for Proxy in second loop to catch both cases :

private function _computeAssociationChanges($assoc, $value)
    {
      .....

        // Look through the entities, and in any of their associations, for transient
        // enities, recursively. ("Persistence by reachability")
        if ($assoc->isOneToOne()) {
            $value = array($value);
        } else if ($value instanceof PersistentCollection) {
            $value = $value->unwrap();
        }

        $targetClass = $this->_em->getClassMetadata($assoc->targetEntityName);
        foreach ($value as $entry) {
           if ($entry instanceof Proxy && ! $entry->*_isInitialized_*) {
               continue; // Ignore uninitialized proxy objects
            }
           .....
        }
    }
Originally created by @doctrinebot on GitHub (Feb 22, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user rickdt: Occurs in trunk revision 7203 We have two entity with an empty oneToMany association Client -> Email When there is no email, I don't know why, the collection is filled with EmailProxy. (Data come from a query hydrated object) in UnitOfWork::_computeAssociationChanges I see there is a test for Proxy entity but it does not apply to collection. ``` private function _computeAssociationChanges($assoc, $value) { ..... // Look through the entities, and in any of their associations, for transient // enities, recursively. ("Persistence by reachability") if ($assoc->isOneToOne()) { if ($value instanceof Proxy && ! $value->*_isInitialized_*) { return; // Ignore uninitialized proxy objects } $value = array($value); } else if ($value instanceof PersistentCollection) { $value = $value->unwrap(); } $targetClass = $this->_em->getClassMetadata($assoc->targetEntityName); foreach ($value as $entry) { ...... } } ``` Maybe you could try to check for Proxy in second loop to catch both cases : ``` private function _computeAssociationChanges($assoc, $value) { ..... // Look through the entities, and in any of their associations, for transient // enities, recursively. ("Persistence by reachability") if ($assoc->isOneToOne()) { $value = array($value); } else if ($value instanceof PersistentCollection) { $value = $value->unwrap(); } $targetClass = $this->_em->getClassMetadata($assoc->targetEntityName); foreach ($value as $entry) { if ($entry instanceof Proxy && ! $entry->*_isInitialized_*) { continue; // Ignore uninitialized proxy objects } ..... } } ```
admin added the Bug label 2026-01-22 12:38:46 +01:00
admin closed this issue 2026-01-22 12:38:47 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 22, 2010):

Comment created by rickdt:

At your request I could do a UnitTest Case

@doctrinebot commented on GitHub (Feb 22, 2010): Comment created by rickdt: At your request I could do a UnitTest Case
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2010):

Comment created by @beberlei:

The unit-test is somehow missing Eric, can you attach it to the issue again?

@doctrinebot commented on GitHub (Feb 26, 2010): Comment created by @beberlei: The unit-test is somehow missing Eric, can you attach it to the issue again?
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2010):

Comment created by rickdt:

That's because nobody asked for it.

Il try to build one and attach it soon.

@doctrinebot commented on GitHub (Feb 26, 2010): Comment created by rickdt: That's because nobody asked for it. Il try to build one and attach it soon.
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2010):

Comment created by rickdt:

I'm sorry, but I'm not able anymore to reproduce this issue.

Maybe some changes in trunk fixed it.

If it occurs again, I will re-open this case.

@doctrinebot commented on GitHub (Feb 26, 2010): Comment created by rickdt: I'm sorry, but I'm not able anymore to reproduce this issue. Maybe some changes in trunk fixed it. If it occurs again, I will re-open this case.
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2010):

Comment created by @beberlei:

DDC-353 was a similiar issue, i think this one should be fixed with DDC-353.

@doctrinebot commented on GitHub (Feb 28, 2010): Comment created by @beberlei: [DDC-353](http://www.doctrine-project.org/jira/browse/DDC-353) was a similiar issue, i think this one should be fixed with [DDC-353](http://www.doctrine-project.org/jira/browse/DDC-353).
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 28, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#452