Skip to content

Loading…

DDC-41: Getting error with lazy loading via createQuery() followed by $em->flush() #4899

Closed
doctrinebot opened this Issue · 4 comments

1 participant

@doctrinebot

Jira issue originally created by user crotalus:

Simple O-O relationship between \Entities\User and \Entities\Feed. Seems like there's a problem with not-yet lazy-loaded proxies and $em->flush().

<?php
namespace Entities;

/*** @Entity @Table(name="users_debug") **/
class User {
    /****
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /****
     * @OneToOne(targetEntity="Feed", mappedBy="User", cascade={"persist"})
     */
    private $Feed;

    public function getID() {
        return $this->id;
    }
    public function getFeed() {
        return $this->Feed;
    }
    public function setFeed($feed) {
        $this->Feed = $feed;
    }
}
?>

<?php
namespace Entities;

/****
 * @Entity @Table(name="feeds_debug")
 */
class Feed {
    /****
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO", allocationSize=1)
     */
    private $id;

     /****
     * @OneToOne(targetEntity="User", cascade={"persist"})
     * @JoinColumn(name="user_id", referencedColumnName="id")
     */
    private $User;

    function setID($value) {
        $this->id = $value;
    }
    function getID() {
        return $this->id;
    }
    function getUser() {
        return $this->User;
    }
    function setUser($user) {
        $this->User = $user;
    }
}


?>

Table-data

users_debug:
 id
 361

feeds_debug:
 id  | user_id
 461 |     361

Code:

$user = $em->createQuery("SELECT u FROM Entities\User u WHERE u.id = 361")->getSingleResult();
print $user->getID(); // 361
// uncomment line below and it works
// print $user->getFeed()->getID();
$em->flush();

Error:
Warning: splobjecthash() expects parameter 1 to be object, null given in /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/UnitOfWork.php on line 1010
Warning: splobjecthash() expects parameter 1 to be object, null given in /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/UnitOfWork.php on line 566
Warning: ReflectionProperty::setValue() expects parameter 1 to be object, null given in /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/UnitOfWork.php on line 575
Warning: get_class() expects parameter 1 to be object, null given in /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/UnitOfWork.php on line 979
Fatal error: Uncaught exception 'ReflectionException' with message 'Class does not exist' in /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/Mapping/ClassMetadata.php:69
Stack trace:
#0 /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/Mapping/ClassMetadata.php(69): ReflectionClass->construct(false)
#1 /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(247): Doctrine\ORM\Mapping\ClassMetadata->
construct(false)
#2 /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(177): Doctrine\ORM\Mapping\ClassMetadataFactory->_newClassMetadataInstance(false)
#3 /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(115): Doctrine\ORM\Mapping\ClassMetadataFactory->_loadMetadata(false)
#4 /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/EntityManager.php(212): Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor(false)
#5 /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/UnitOfWork.php(979): Doctrine\ORM\EntityManager->getClassMetadata in /home/crotalus/src/Doctrine2-Dev/lib/Doctrine/ORM/Mapping/ClassMetadata.php on line 69

PostgreSQL log:
2009-10-10 16:32:58 CEST LOGG: execute pdostmt_000000000a283af8: SELECT u0_.id AS id0 FROM users_debug u0_ WHERE u0.id = 361
2009-10-10 16:32:58 CEST LOGG: sats: DEALLOCATE pdostmt000000000a283af8
2009-10-10 16:32:58 CEST LOGG: execute pdostmt_000000000a283af8: SELECT NEXTVAL('feeds_debug_idseq')
2009-10-10 16:32:58 CEST LOGG: sats: DEALLOCATE pdostmt000000000a283af8
2009-10-10 16:32:58 CEST LOGG: execute pdostmt_000000000a283af8: SELECT NEXTVAL('users_debug_idseq')
2009-10-10 16:32:58 CEST LOGG: sats: DEALLOCATE pdostmt000000000a283af8

@doctrinebot

Comment created by romanb:

Strange, all the warnings and errors and the stack trace rather indicate that the associated value is NULL and not a (not initialized) proxy object. I'm working on this and already found an issue to address but I'm still unable to exactly reproduce this. Will keep you updated. If you have any further information, please let me know.

@doctrinebot

Comment created by romanb:

OK, managed to reproduce this. Working on it.

@doctrinebot

Comment created by romanb:

This should now be fixed but you need to manually delete your proxy classes so that they're regenerated. More improvements to the proxy classes and CLI tasks for (re)generating proxy classes will follow.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-ALPHA3 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.