Skip to content

Loading…

DDC-1942: problem with serialize/merging entities with aggregation #2613

Closed
doctrinebot opened this Issue · 21 comments

2 participants

@doctrinebot

Jira issue originally created by user gabrielnn77:

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;
}

Clase01 have two aggregation association with Clase03

Clase*01 ------> Clase*03
         |-----> Clase*03*1

when serialize an object of class Clase01 and then unserialize, i lost the reference to the object of class Clase03
but i can see Clase031

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 getclase_03() before detach the object, i can see the object Clase03
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]
@doctrinebot

Comment created by gabrielnn77:

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]
@doctrinebot

Comment created by amarquez:

i have the same problem

@doctrinebot

Comment created by @beberlei:

formatted code

@doctrinebot

Comment created by @beberlei:

Can you paste a vardump() 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 $auxs

@doctrinebot

Comment created by gabrielnn77:

var_dump in attached file

@doctrinebot

Comment created by gabrielnn77:

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

@doctrinebot

Comment created by gsesia:

I have same problems

@doctrinebot

Comment created by gabrielnn77:

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

@doctrinebot

Comment created by valentin:

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 ?

@doctrinebot

Comment created by valentin:

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.

@doctrinebot

Comment created by @ocramius:

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

[~gabrielnn77] can you please try initializing ALL of these related objects prior to detaching/serializing and repeat your checks?

@doctrinebot

Comment created by gabrielnn77:

How do I have to initialize the objects?

@doctrinebot

Comment created by @ocramius:

[~gabrielnn77] by calling any method that is not getId on them.
This will initialize them

@doctrinebot

Comment created by @ocramius:

[~gabrielnn77] news on this one? Managed to verify it?

@doctrinebot

Comment created by @ocramius:

This may be a duplicate of DDC-2306

@doctrinebot

Comment created by @beberlei:

A related Github Pull-Request [GH-585] was closed
#585

@doctrinebot

Issue was closed with resolution "Duplicate"

@doctrinebot

Comment created by @ocramius:

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

@doctrinebot

Comment created by @doctrinebot:

A related Github Pull-Request [GH-585] was closed:
doctrine/dbal#585

@doctrinebot

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1172] was assigned:
#1172

@doctrinebot

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1172] was closed:
#1172

@Ocramius Ocramius was assigned by doctrinebot
@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.