[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 |