[DDC-3524] [GH-1272] [DDC-2704] - merge inherited transient properties - merge properties into uninitialized proxies Created: 20/Jan/15  Updated: 25/Jan/15  Resolved: 25/Jan/15

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: Git Master, 2.4.7
Fix Version/s: 2.5
Security Level: All

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Marco Pivetta
Resolution: Fixed Votes: 0
Labels: inheritance, merge, private-properties, transient-properties, unitofwork

Issue Links:
Dependency
is required for DDC-2704 When using Discriminator EntityManage... Resolved

 Description   

This issue is created automatically through a Github pull request on behalf of Ocramius:

Url: https://github.com/doctrine/doctrine2/pull/1272

Message:

See http://www.doctrine-project.org/jira/browse/DDC-2704 - DDC-2704



 Comments   
Comment by Doctrine Bot [ 24/Jan/15 ]

A related Github Pull-Request [GH-1272] was unlabeled:
https://github.com/doctrine/doctrine2/pull/1272

Comment by Doctrine Bot [ 25/Jan/15 ]

A related Github Pull-Request [GH-1272] was merged:
https://github.com/doctrine/doctrine2/pull/1272





[DDC-3378] [GH-1176] Support merging entities with composite identities defined through to-one associations Created: 07/Nov/14  Updated: 22/Jan/15  Resolved: 22/Jan/15

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: Git Master, 2.4.7
Fix Version/s: 2.5
Security Level: All

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Marco Pivetta
Resolution: Fixed Votes: 0
Labels: association, composite-identifier, identifier, many-to-one, merge, one-to-one


 Description   

This issue is created automatically through a Github pull request on behalf of adrienbrault:

Url: https://github.com/doctrine/doctrine2/pull/1176

Message:

I hope that I'm doing something wrong and that this is not a bug ...



 Comments   
Comment by Doctrine Bot [ 22/Jan/15 ]

A related Github Pull-Request [GH-1176] was assigned:
https://github.com/doctrine/doctrine2/pull/1176

Comment by Doctrine Bot [ 22/Jan/15 ]

A related Github Pull-Request [GH-1176] was closed:
https://github.com/doctrine/doctrine2/pull/1176





[DDC-3370] [GH-1173] Fix merging of entities with associations to identical entities. Created: 05/Nov/14  Updated: 11/Nov/14  Resolved: 11/Nov/14

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.3.5, 2.4.6
Fix Version/s: 2.5
Security Level: All

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Marco Pivetta
Resolution: Fixed Votes: 0
Labels: cascade, merge, unitofwork


 Description   

This issue is created automatically through a Github pull request on behalf of mathieudz:

Url: https://github.com/doctrine/doctrine2/pull/1173

Message:

Without this patch, when an entity that refers multiple times to the same
associated entity gets merged, the second references becomes null.

The main issue is that even though doMerge returns a managed copy, that value
is not used while cascading the merge. These identicial entities are already
detected through the visitor map, but they are ignored. There should be some
refactoring so cascadeMerge calls a function that checks if the parent must be
updated, based on the return value of its call to doMerge. However, this patch
tries to impact the code as little as possible, and only introduces a new
function to avoid duplicate code.

The secondary issue arises when using inverted associations. In that case, it
is possible that an entity to be merged is already merged, so the the visitor
map is looked up by the hash of a managed copy instead of the original entity.
This means that in this case the visitor map entries should also be set to the
entity, instead of being set to 'true'.



 Comments   
Comment by Doctrine Bot [ 11/Nov/14 ]

A related Github Pull-Request [GH-1173] was assigned:
https://github.com/doctrine/doctrine2/pull/1173

Comment by Doctrine Bot [ 11/Nov/14 ]

A related Github Pull-Request [GH-1173] was closed:
https://github.com/doctrine/doctrine2/pull/1173





[DDC-3368] [GH-1172] Don't initialize detached proxies when merging them. Created: 02/Nov/14  Updated: 16/Jan/15  Resolved: 16/Jan/15

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: Lazy Loading, ORM
Affects Version/s: Git Master, 2.4.6, 2.4.7
Fix Version/s: 2.5
Security Level: All

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Marco Pivetta
Resolution: Fixed Votes: 0
Labels: lazy-loading, merge, proxy

Issue Links:
Reference
relates to DDC-1392 Merge for not initialized entity prox... Resolved
relates to DDC-1734 Uninitialized proxies cannot be seria... Resolved

 Description   

This issue is created automatically through a Github pull request on behalf of mathieudz:

Url: https://github.com/doctrine/doctrine2/pull/1172

Message:

Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of unserialized uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.

Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.

Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.

Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.



 Comments   
Comment by Doctrine Bot [ 12/Nov/14 ]

A related Github Pull-Request [GH-1172] was assigned:
https://github.com/doctrine/doctrine2/pull/1172

Comment by Doctrine Bot [ 16/Jan/15 ]

A related Github Pull-Request [GH-1172] was closed:
https://github.com/doctrine/doctrine2/pull/1172





[DDC-3315] [GH-1140] [DDC-2704] merge throughout entity hierarchy Created: 19/Sep/14  Updated: 25/Jan/15  Resolved: 15/Jan/15

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: Git Master, 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Marco Pivetta
Resolution: Incomplete Votes: 0
Labels: inheritance, merge


 Description   

This issue is created automatically through a Github pull request on behalf of tiger-seo:

Url: https://github.com/doctrine/doctrine2/pull/1140

Message:



 Comments   
Comment by Doctrine Bot [ 15/Jan/15 ]

A related Github Pull-Request [GH-1140] was closed:
https://github.com/doctrine/doctrine2/pull/1140

Comment by Doctrine Bot [ 15/Jan/15 ]

A related Github Pull-Request [GH-1140] was assigned:
https://github.com/doctrine/doctrine2/pull/1140

Comment by Doctrine Bot [ 24/Jan/15 ]

A related Github Pull-Request [GH-1272] was unlabeled:
https://github.com/doctrine/doctrine2/pull/1272

Comment by Doctrine Bot [ 25/Jan/15 ]

A related Github Pull-Request [GH-1272] was merged:
https://github.com/doctrine/doctrine2/pull/1272





[DDC-2704] When using Discriminator EntityManager#merge fails Created: 25/Sep/13  Updated: 25/Jan/15  Resolved: 25/Jan/15

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4, 2.4.2
Fix Version/s: 2.5
Security Level: All

Type: Bug Priority: Major
Reporter: Vladyslav Petrovych Assignee: Marco Pivetta
Resolution: Fixed Votes: 2
Labels: inheritance, merge, private-properties, transient-properties, unitofwork

Issue Links:
Dependency
depends on DDC-3524 [GH-1272] [DDC-2704] - merge inherite... Resolved

 Description   

I have the following hierarchy:

  • AgentConfig has relation ManyToOne with AgentTask.
  • AgentTask has DiscriminatorColumn & DiscriminatorMap assigned to it.
  • AgentTask has relation ManyToOne with AgentTaskConfig.

I believe the problem is because of the following:

UnitOfWork#doMerge has the tries to get properties the following way:

// Merge state of $entity into existing (managed) entity
foreach ($class->reflClass->getProperties() as $prop) {

This obviously doesn't get the parent class (AgentTask) properties.

Later on UnitOfWork fails on line:

$prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->add($managedCopy);

because $prevManagedCopy doesn't have properties set from entity.

My proposal is to get the properties the following way:

$properties = $class->reflClass->getProperties();
$parent = $class->reflClass;
while (($parent = $parent->getParentClass()) != null) {
    $properties = array_merge($parent->getProperties(), $properties);
}

// Merge state of $entity into existing (managed) entity
foreach ($properties as $prop) {


 Comments   
Comment by Rasmus Jensen [ 20/Jan/15 ]

I have this problem as well in .
The Merge operation does not copy properties of any parent class to the managed copy. My workaround when merging entities with inheritance is:
1. Receive detached entity that is instance of a subclass.
2. fetch a managed copy of the entity from database with id of detached entity.
3. manually set properties on the managed entity.
4. flush to save changes.

This is obviously only manageable with a relatively simple datastructure, and quickly becomes very messy with more complex entities and relationship hierarchies.

Would really appreciate a fix for this

Comment by Marco Pivetta [ 20/Jan/15 ]

A temporary workaround is to change properties into protected. I'll mark this for 2.5 and see if it can be fixed by then.

Comment by Marco Pivetta [ 25/Jan/15 ]

Handled in DDC-3524





[DDC-2645] merge() not dealing correctly with composite primary keys Created: 02/Sep/13  Updated: 15/Dec/13  Resolved: 15/Dec/13

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

Type: Bug Priority: Major
Reporter: Pouyan Savoli Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 1
Labels: composite, merge, orm


 Description   

$entity=$em->merge($entity);

fails for entity with composite keys:
http://pastebin.com/iz6UACf9


Calling flattenIdentifier() from:

returns only array of foreign keys (integer primary key ignored)

Causing this exception to be thrown:



 Comments   
Comment by Pouyan Savoli [ 20/Sep/13 ]

I haven't seen any comments or progress on this issue.

So I came up with a fix for flattenIdentifier my self:
http://pastebin.com/hvVRaU8z

Can this be pushed to repos once its validated?

Comment by Lars Heß [ 02/Dec/13 ]

Same problem here, please fix this issue asap! )

Comment by Benjamin Eberlei [ 15/Dec/13 ]

Fixed and merged for 2.4.2





[DDC-2354] [GH-617] Wrong UnitOfWork::computeChangeSet() Created: 16/Mar/13  Updated: 11/Nov/14  Resolved: 11/Nov/14

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

Type: Bug Priority: Major
Reporter: Benjamin Eberlei Assignee: Marco Pivetta
Resolution: Cannot Reproduce Votes: 0
Labels: listener, merge, proxy


 Description   

This issue is created automatically through a Github pull request on behalf of fchris82:

Url: https://github.com/doctrine/doctrine2/pull/617

Message:

Sometimes some fields are Proxy when compute "changeSet". If it is Proxy, some listeners - example Gedmo sortable listener - belive the value has changed and this leads to chaos.

I check the $actualValue, if it is Proxy, the value didn't change.



 Comments   
Comment by Doctrine Bot [ 11/Nov/14 ]

A related Github Pull-Request [GH-617] was closed:
https://github.com/doctrine/doctrine2/pull/617

Comment by Doctrine Bot [ 11/Nov/14 ]

A related Github Pull-Request [GH-617] was assigned:
https://github.com/doctrine/doctrine2/pull/617





[DDC-2146] Detach and merge cascading not working properly Created: 15/Nov/12  Updated: 08/Sep/13  Resolved: 08/Sep/13

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

Type: Bug Priority: Major
Reporter: Nick Walke Assignee: Benjamin Eberlei
Resolution: Invalid Votes: 0
Labels: cascade, detach, merge


 Description   

The problem is described in detail here: http://stackoverflow.com/questions/13372305/doctrine-detaching-caching-and-merging

No one on IRC seems to know why this won't work. I was using 2.2.2, I've since updated to 2.3 and I'm still seeing the same issue.



 Comments   
Comment by Nick Walke [ 15/Nov/12 ]

This was a typo on my part. Disregard.





[DDC-2033] Merge with multiple Associations to the same Entity Created: 17/Sep/12  Updated: 23/Jan/13  Resolved: 23/Jan/13

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

Type: Bug Priority: Major
Reporter: sören jahns Assignee: Marco Pivetta
Resolution: Duplicate Votes: 1
Labels: merge
Environment:

Symfony 2.1.1, Ubuntu, PHP 5.3.5


Attachments: File Group.php     File User.php    

 Description   

Let's say we have 2 Entities. User and Group and there's a ManyToMany Assocication and an additional ManyToOne (User as owning side and no inverse).

So a User can have as many Groups as he likes and one another with the ManyToOne Association which can be also in the ManyToMany Collection. (Could be the MainGroup or something)

I create a User and add a Group(already in DB) and set the same as the ManyToOne and Merge it. Everything works fine as long as the Group in ManyToOne Association is not in the ManyToMany.

If I var_dump the merged entity i can already see that one association is empty.

It looks like doctrine is writing just one association of that Group preferring which one comes first. So if i change the position of the properties in the class the written association changes, but doctrine never writes both.

The reason why I use merge is that I normally store the entity in the session and merge and flush it in another request. But this also happens in the same Request.

In the UnitofWork at Line 2050 and 2053 are the responsible doMerge Calls for as CascadeMerge Tagged Associations. If Doctrine gets there in the first place the doMerge for the Group is running through. In the Second call when the Group is again associated with the user the doMerge already exits at line 1658. That's ok but I think there's something missing so doctrine isn't creating the association.

The Mentioned Entites are attached



 Comments   
Comment by Marco Pivetta [ 23/Jan/13 ]

Duplicate of DDC-1942





[DDC-1942] problem with serialize/merging entities with aggregation Created: 24/Jul/12  Updated: 16/Jan/15  Resolved: 27/Feb/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.2.2
Fix Version/s: None

Type: Bug Priority: Major
Reporter: gabriel sancho Assignee: Marco Pivetta
Resolution: Duplicate Votes: 3
Labels: merge, serialize
Environment:

linux, php 5.4.4, apache 2.2.22, mysql 5.5


Attachments: Text File project_debug.log    

 Description   

i have these two entities:

namespace nuevo_paquete;

class Clase_01{
	/**
	* @Id
	* @Column(name="id",type="integer",nullable=false)
	* @GeneratedValue
	*/
	protected $id;
        
        /**
	* @ManyToOne(targetEntity="\paquete_02\Clase_03", inversedBy="clase_01", fetch="EXTRA_LAZY", cascade={"detach","merge"})
	* @JoinColumn(name="clase_03", referencedColumnName="id")
	*/
	protected $clase_03;

        /**
	* @ManyToOne(targetEntity="\paquete_02\Clase_03", inversedBy="clase_01_1", fetch="EXTRA_LAZY", cascade={"detach","merge"})
	* @JoinColumn(name="clase_03_1", referencedColumnName="id")
	*/
	protected $clase_03_1;
}
namespace paquete_02;
class Clase_03{
   /**
	* @Id
	* @Column(name="id",type="integer",nullable=false)
	* @GeneratedValue
	*/
	protected $id;

        /**
	* @OneToMany(targetEntity="\nuevo_paquete\Clase_01", mappedBy="clase_03", fetch="EXTRA_LAZY", cascade={"detach"})
	*/
	protected $clase_01;
	
	/**
	* @OneToMany(targetEntity="\nuevo_paquete\Clase_01", mappedBy="clase_03_1", fetch="EXTRA_LAZY", cascade={"detach"})
	*/
	protected $clase_01_1;
}

Clase_01 have two aggregation association with Clase_03

Clase_01 ------> Clase_03

-----> Clase_03_1

when serialize an object of class Clase_01 and then unserialize, i lost the reference to the object of class Clase_03
but i can see Clase_03_1

ej:

$aux_orm = $em->find('nuevo_paquete\Clase_01', 1);
$em->detach($aux_orm);
$aux_s = serialize($aux_orm);
$aux_orm = unserialize($aux_s);

$aux_orm = $em->merge($aux_orm);
echo '['.$aux_orm->getId().']'; // [1]
echo '['.$aux_orm->getClase_03()->getId().']'; // [] expected : [1]
echo '['.$aux_orm->getClase_03_1()->getId().']'; // [1]

when i call get_clase_03() before detach the object, i can see the object Clase_03
ej:

$aux_orm = $em->find('nuevo_paquete\Clase_01', 1);
$aux_orm->getClase_03()->getId();

$em->detach($aux_orm);
$aux_s = serialize($aux_orm);
$aux_orm = unserialize($aux_s);

$aux_orm = $em->merge($aux_orm);
echo '['.$aux_orm->getId().']'; // [1]
echo '['.$aux_orm->getClase_03()->getId().']'; // [1]
echo '['.$aux_orm->getClase_03_1()->getId().']'; // [1]


 Comments   
Comment by gabriel sancho [ 24/Jul/12 ]

if i call $em->find() i still not able to view the object

//----------------------------------------
$aux_orm = $em->find('nuevo_paquete\Clase_01', 1);
$em->detach($aux_orm);
$aux_s = serialize($aux_orm);
$aux_orm = unserialize($aux_s);

$aux_orm = $em->merge($aux_orm);
echo '['.$aux_orm->getId().']'; // [1]
echo '['.$aux_orm->getClase_03()->getId().']'; // [] expected : [1]
echo '['.$aux_orm->getClase_03_1()->getId().']'; // [1]

$aux_orm = $em->find('nuevo_paquete\Clase_01', 1);
echo '['.$aux_orm->getId().']'; // [1]
echo '['.$aux_orm->getClase_03()->getId().']'; // still empty [] expected : [1]

//----------------------------------------
and if i have another register referencing the same object of class_03, i can't view
ej:

$aux_orm = $em->find('nuevo_paquete\Clase_01', 2);
echo '['.$aux_orm->getId().']'; // [2]
echo '['.$aux_orm->getClase_03()->getId().']'; // still empty [] expected : [1]
Comment by Marquez Alejandra [ 24/Jul/12 ]

i have the same problem

Comment by Benjamin Eberlei [ 29/Jul/12 ]

formatted code

Comment by Benjamin Eberlei [ 29/Jul/12 ]

Can you paste a var_dump() of class1 after you call detach and before serialize and then another one after you called unserialize? Also a var_dump of the serialized string $aux_s

Comment by gabriel sancho [ 30/Jul/12 ]

var_dump in attached file

Comment by gabriel sancho [ 11/Sep/12 ]

i found that if the class has more than two levels have the same problem
by ex. i have to do

// class1 -> register id 1
// class2 -> register id 1
// class3 -> null, don't exist
$class2 = $class1->getClass2();
$class3 = $class2->getClass3();
$class3->getId();

otherwise doctrine insert new registers in database for class3
after unserialize

Comment by gonzalo [ 11/Sep/12 ]

I have same problems

Comment by gabriel sancho [ 11/Sep/12 ]

if i declare in the entity annotation fetch="EAGER" works fine

Comment by Valentin Claras [ 11/Dec/12 ]

I have the same problem.

From what I saw, if I use fetch: EAGER, all my distinct entities are merged indeed, but if a specific entity (instance) is in two different collections, only one collection will have this instance.

So, any news about this bug ?

Comment by Valentin Claras [ 13/Dec/12 ]

I'm still trying to get my stuff works, and I'm now pretty sure that as soon as an object have to be merge more than once in a row (because of cascade associations), it end up being only in one collection, and lost for other entities.

I hope this could help.

Comment by Marco Pivetta [ 23/Jan/13 ]

I think this one is also related with DDC-1734 (noticed a lot of un-initialized objects).

gabriel sancho can you please try initializing ALL of these related objects prior to detaching/serializing and repeat your checks?

Comment by gabriel sancho [ 24/Jan/13 ]

How do I have to initialize the objects?

Comment by Marco Pivetta [ 24/Jan/13 ]

gabriel sancho by calling any method that is not `getId` on them.
This will initialize them

Comment by Marco Pivetta [ 23/Feb/13 ]

gabriel sancho news on this one? Managed to verify it?

Comment by Marco Pivetta [ 23/Feb/13 ]

This may be a duplicate of DDC-2306

Comment by Benjamin Eberlei [ 26/Feb/13 ]

A related Github Pull-Request [GH-585] was closed
https://github.com/doctrine/doctrine2/pull/585

Comment by Marco Pivetta [ 27/Feb/13 ]

This issue is valid only before the fix introduced at DDC-2306. Duplicate confirmed

Comment by Doctrine Bot [ 29/Apr/14 ]

A related Github Pull-Request [GH-585] was closed:
https://github.com/doctrine/dbal/pull/585

Comment by Doctrine Bot [ 12/Nov/14 ]

A related Github Pull-Request [GH-1172] was assigned:
https://github.com/doctrine/doctrine2/pull/1172

Comment by Doctrine Bot [ 16/Jan/15 ]

A related Github Pull-Request [GH-1172] was closed:
https://github.com/doctrine/doctrine2/pull/1172





Generated at Tue Mar 31 11:34:40 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.