Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
doctrinebot opened this issue Jul 24, 2012 · 21 comments
Closed

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

doctrinebot opened this issue Jul 24, 2012 · 21 comments
Assignees
Labels

Comments

@doctrinebot
Copy link

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

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]
@doctrinebot
Copy link
Author

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
Copy link
Author

Comment created by amarquez:

i have the same problem

@doctrinebot
Copy link
Author

Comment created by @beberlei:

formatted code

@doctrinebot
Copy link
Author

Comment created by @beberlei:

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

@doctrinebot
Copy link
Author

Comment created by gabrielnn77:

var_dump in attached file

@doctrinebot
Copy link
Author

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
Copy link
Author

Comment created by gsesia:

I have same problems

@doctrinebot
Copy link
Author

Comment created by gabrielnn77:

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

@doctrinebot
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Comment created by gabrielnn77:

How do I have to initialize the objects?

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

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

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

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

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

This may be a duplicate of DDC-2306

@doctrinebot
Copy link
Author

Comment created by @beberlei:

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

@doctrinebot
Copy link
Author

Issue was closed with resolution "Duplicate"

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

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

@doctrinebot
Copy link
Author

Comment created by @doctrinebot:

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

@doctrinebot
Copy link
Author

Comment created by @doctrinebot:

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

@doctrinebot
Copy link
Author

Comment created by @doctrinebot:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants