DDC-1054: Lazy loading problem #1318

Closed
opened 2026-01-22 13:10:07 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 2, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user vigor_bg:

I have a problem when using lazy loading in entity that was initialized before that through eager loading. I am attaching a file with my entities and the 2 queries that i make whit which i have the problem.

Originally created by @doctrinebot on GitHub (Mar 2, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user vigor_bg: I have a problem when using lazy loading in entity that was initialized before that through eager loading. I am attaching a file with my entities and the 2 queries that i make whit which i have the problem.
admin added the Bug label 2026-01-22 13:10:07 +01:00
admin closed this issue 2026-01-22 13:10:08 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 2, 2011):

Comment created by vigor_bg:

There is a fix that i made to fix the problem, but i am not sure how it will reflect on the performance. But as far as i can see and understand the logic i don't see where else it could be.

in the class ObjectHydrator in privet function _initRelatedCollection
on line 164 you make a check if collection is set to be refreshed or it is fetched but not initialized.


else if (isset($this->*hints[Query::HINT*REFRESH]) ||
                isset($this->_hints['fetched'][$class->name][$fieldName]) &&
                ! $value->isInitialized()) {
            // Is already PersistentCollection, but either REFRESH or FETCH-JOIN and UNINITIALIZED!
            $value->setDirty(false);
            $value->setInitialized(true);
            $value->unwrap()->clear();
            $this->_initializedCollections[$oid . $fieldName] = $value;
        }

The problem that i see here is in the second part when the collection is not initialized and i think that is the reason for the problem so my solution si


else if (isset($this->*hints[Query::HINT*REFRESH]) ||
                isset($this->_hints['fetched'][$class->name][$fieldName]) &&
                ! $value->isInitialized()) {
            // Is already PersistentCollection, but either REFRESH or FETCH-JOIN and UNINITIALIZED!
            $value->setDirty(false);
       /****
            *  $value->setInitialized(true);
            *  $value->unwrap()->clear();
            * Fix by Victor on 02/03/2011
            * With only that code the collection doesn't get initialized
            */
            $value->initialize();
            $this->_initializedCollections[$oid . $fieldName] = $value;
        }
@doctrinebot commented on GitHub (Mar 2, 2011): Comment created by vigor_bg: There is a fix that i made to fix the problem, but i am not sure how it will reflect on the performance. But as far as i can see and understand the logic i don't see where else it could be. in the class ObjectHydrator in privet function _initRelatedCollection on line 164 you make a check if collection is set to be refreshed or it is fetched but not initialized. ``` else if (isset($this->*hints[Query::HINT*REFRESH]) || isset($this->_hints['fetched'][$class->name][$fieldName]) && ! $value->isInitialized()) { // Is already PersistentCollection, but either REFRESH or FETCH-JOIN and UNINITIALIZED! $value->setDirty(false); $value->setInitialized(true); $value->unwrap()->clear(); $this->_initializedCollections[$oid . $fieldName] = $value; } ``` The problem that i see here is in the second part when the collection is not initialized and i think that is the reason for the problem so my solution si ``` else if (isset($this->*hints[Query::HINT*REFRESH]) || isset($this->_hints['fetched'][$class->name][$fieldName]) && ! $value->isInitialized()) { // Is already PersistentCollection, but either REFRESH or FETCH-JOIN and UNINITIALIZED! $value->setDirty(false); /**** * $value->setInitialized(true); * $value->unwrap()->clear(); * Fix by Victor on 02/03/2011 * With only that code the collection doesn't get initialized */ $value->initialize(); $this->_initializedCollections[$oid . $fieldName] = $value; } ```
Author
Owner

@doctrinebot commented on GitHub (Mar 4, 2011):

Comment created by @beberlei:

"I am having a problem".

Can you describe a little bit more what your problem actually is?

@doctrinebot commented on GitHub (Mar 4, 2011): Comment created by @beberlei: "I am having a problem". Can you describe a little bit more what your problem actually is?
Author
Owner

@doctrinebot commented on GitHub (Mar 5, 2011):

Comment created by vigor_bg:

well that is why i have attached the php file. Inside you can see my entities and the 2 queries whit which i have the problem. So in general when i call entity and use eager join to get related entity. And then call that related entity on it's own the lazy loading is not working.

@doctrinebot commented on GitHub (Mar 5, 2011): Comment created by vigor_bg: well that is why i have attached the php file. Inside you can see my entities and the 2 queries whit which i have the problem. So in general when i call entity and use eager join to get related entity. And then call that related entity on it's own the lazy loading is not working.
Author
Owner

@doctrinebot commented on GitHub (Mar 20, 2011):

Comment created by @beberlei:

In your use-case do you execute Q1 and then Q2 after each other in the same request? I just don't get why in your case a query with a Refresh Hint is executed.

The code is not very helpful as i cannot execute it out of the box. I would prefer a PHPUnit test-case with one of the Doctrine2 Test Models for such a complex issue.

@doctrinebot commented on GitHub (Mar 20, 2011): Comment created by @beberlei: In your use-case do you execute Q1 and then Q2 after each other in the same request? I just don't get why in your case a query with a Refresh Hint is executed. The code is not very helpful as i cannot execute it out of the box. I would prefer a PHPUnit test-case with one of the Doctrine2 Test Models for such a complex issue.
Author
Owner

@doctrinebot commented on GitHub (Mar 25, 2011):

Comment created by vigor_bg:

After i updated to the latest version the bug was fixed. So sorry for the bother. Looks like it was connected with the problem of ticket DDC-992.
Thanks for the great work :)

@doctrinebot commented on GitHub (Mar 25, 2011): Comment created by vigor_bg: After i updated to the latest version the bug was fixed. So sorry for the bother. Looks like it was connected with the problem of ticket [DDC-992](http://www.doctrine-project.org/jira/browse/DDC-992). Thanks for the great work :)
Author
Owner

@doctrinebot commented on GitHub (Mar 25, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Mar 25, 2011): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/8346745114f8d5ca524e

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/8346745114f8d5ca524e - [10948_Doctrine LazyLoad.php](https://gist.github.com/8346745114f8d5ca524e#file-10948_Doctrine LazyLoad-php)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1318