[DDC-2146] Detach and merge cascading not working properly Created: 15/Nov/12 Updated: 15/Nov/12 Resolved: 15/Nov/12 |
|
| 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: | Fixed | 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: |
|
| 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] problem with serialize/merging entities with aggregation Created: 24/Jul/12 Updated: 27/Feb/13 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: |
|
| 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
when serialize an object of class Clase_01 and then unserialize, i lost the reference to the object of class Clase_03 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
$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] //----------------------------------------
$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 // 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 |
| 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 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. |
| 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 |
| Comment by Benjamin Eberlei [ 26/Feb/13 ] |
|
A related Github Pull-Request [GH-585] was closed |
| Comment by Marco Pivetta [ 27/Feb/13 ] |
|
This issue is valid only before the fix introduced at |