Doctrine Project

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Doctrine 2 - ORM
  • Doctrine 2 - ORM
  • DDC-1054

Lazy loading problem

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0.1
  • Fix Version/s: 2.0.4
  • Component/s: ORM
  • Security Level: All
  • Labels:
    None

Description

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.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. File
    Doctrine LazyLoad.php
    02/Mar/11 3:30 AM
    3 kB
    victor Velkov

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
  • Source
Hide
Permalink
victor Velkov added a comment - 02/Mar/11 3:41 AM

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;
        }
Show
victor Velkov added a comment - 02/Mar/11 3:41 AM 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; }
Hide
Permalink
Benjamin Eberlei added a comment - 04/Mar/11 4:30 PM

"I am having a problem".

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

Show
Benjamin Eberlei added a comment - 04/Mar/11 4:30 PM "I am having a problem". Can you describe a little bit more what your problem actually is?
Hide
Permalink
victor Velkov added a comment - 05/Mar/11 7:12 AM

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.

Show
victor Velkov added a comment - 05/Mar/11 7:12 AM 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.
Hide
Permalink
Benjamin Eberlei added a comment - 20/Mar/11 8:01 AM

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.

Show
Benjamin Eberlei added a comment - 20/Mar/11 8:01 AM 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.
Hide
Permalink
victor Velkov added a comment - 25/Mar/11 9:57 AM

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

Show
victor Velkov added a comment - 25/Mar/11 9:57 AM 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

People

  • Assignee:
    Benjamin Eberlei
    Reporter:
    victor Velkov
Vote (0)
Watch (0)

Dates

  • Created:
    02/Mar/11 3:30 AM
    Updated:
    05/Apr/11 1:22 PM
    Resolved:
    25/Mar/11 9:57 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Doctrine Project. Try JIRA - bug tracking software for your team.