[DDC-446] Cached resultset do not add Entities in UnitOfWork Created: 19/Mar/10  Updated: 30/Oct/11  Resolved: 30/Oct/11

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: 2.2
Security Level: All

Type: Improvement Priority: Major
Reporter: Guilherme Blanco Assignee: Roman S. Borschel
Resolution: Fixed Votes: 1
Labels: None

Attachments: File DDC446Test.php    
Issue Links:
Reference
relates to DDC-217 Result cache should cache the SQL res... Resolved

 Description   

When using resultset cache, when you fetch for these object and attempt to manipulate them, they fail to work giving this message:

Notice:  Undefined index: 000000006f95482300000000384dffac in /srv/app/library/Doctrine/ORM/UnitOfWork.php on line 1901


 Comments   
Comment by Roman S. Borschel [ 20/Mar/10 ]

Objects coming from the result cache are all detached. The EM does not care about them unless you merge() them. But there should probably be a better exception instead of this notice. Please show the code that causes the notice.

PS: Result caching objects is inefficient.

Comment by Guilherme Blanco [ 20/Mar/10 ]

Test case attached.

This is a situation where it should work smoothly IMHO.

Comment by Roman S. Borschel [ 20/Mar/10 ]

No, it should not work smoothly because $user is a detached object. It should throw an exception but the problem is that its hard to detect whether an object is detached in _doPersist.

Comment by Roman S. Borschel [ 20/Mar/10 ]

You need to understand the difference between managed and detached. Its very important.

Comment by Guilherme Blanco [ 20/Mar/10 ]

Adding merge doesn't work too.... same error.

Juyst add $this->_em->merge($user); in line 52.

Comment by Roman S. Borschel [ 20/Mar/10 ]

Of course it wouldnt because thats not how merge works. Merge returns a managed copy.

So you would do:

$managedUser = $this->_em->merge($user);

...

$article->setUser($managedUser);

...
Comment by Roman S. Borschel [ 20/Mar/10 ]

http://www.doctrine-project.org/documentation/manual/2_0/en/working-with-objects:merging-entities

Comment by Benjamin Eberlei [ 30/Oct/11 ]

Implemented through DDC-217

Generated at Mon Sep 22 12:29:27 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.