[DDC-2339] [GH-605] DDC-2338 Added failing test for composite foreign key persistance Created: 07/Mar/13  Updated: 12/Nov/14  Resolved: 12/Nov/14

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

Type: Improvement Priority: Major
Reporter: Benjamin Eberlei Assignee: Marco Pivetta
Resolution: Can't Fix Votes: 0
Labels: autoincrement, commitorder, generation, identifier, identity, sequence

Issue Links:
Dependency
is required for DDC-2338 Entity with composite foreign keys id... Resolved
Reference
relates to DDC-3389 [GH-1184] Postgres SERIAL is not a po... Resolved

 Description   

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

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

Message:

I've added this test regarding ticket DDC-2338



 Comments   
Comment by Benjamin Eberlei [ 09/May/13 ]

This is documented behavior and would just be an improvement

Comment by Doctrine Bot [ 13/May/14 ]

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

Comment by Doctrine Bot [ 12/Nov/14 ]

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





[DDC-2338] Entity with composite foreign keys identifiers should be persisted after related entities without exception Created: 07/Mar/13  Updated: 12/Nov/14  Resolved: 12/Nov/14

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

Type: Improvement Priority: Minor
Reporter: Alessandro Tagliapietra Assignee: Marco Pivetta
Resolution: Can't Fix Votes: 0
Labels: autoincrement, commitorder, identifier, identity, orm, sequence, unitofwork
Environment:

Mac OSX 10.8, php 5.4.11, doctrine git master version


Issue Links:
Dependency
depends on DDC-2339 [GH-605] DDC-2338 Added failing test ... Resolved
Reference
relates to DDC-3389 [GH-1184] Postgres SERIAL is not a po... Resolved

 Description   

I've seen that when you create an entity with a composite foreign key as identifier it cannot be flushed until the related entities are already flushed to the database and not just persisted.

It would be nice to let the user flush all the entities together and just INSERT first the related entities to get the ID and then use that to INSERT the entity with composite foreign keys.

I'm going to create a pull request with the failing test.



 Comments   
Comment by Alessandro Tagliapietra [ 07/Mar/13 ]

Created pull request https://github.com/doctrine/doctrine2/pull/605

Comment by Doctrine Bot [ 12/Nov/14 ]

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

Comment by Marco Pivetta [ 12/Nov/14 ]

Known limitation affecting only post-insert ID generation (mysql et simila)





[DDC-1974] @OneToOne and @InheritanceType cause Duplicate Key Errors when changing the entity Created: 09/Aug/12  Updated: 29/Aug/12  Resolved: 29/Aug/12

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

Type: Bug Priority: Major
Reporter: Philipp Dobrigkeit Assignee: Benjamin Eberlei
Resolution: Won't Fix Votes: 0
Labels: commitorder
Environment:

Win 7, PHP 5.3, MySQL InnoDB



 Description   
<?php

/** @Entity */
class A
{
    /**
     * @Id @Column(name="id", type="integer")
     */
    private $id;

    /**
     * @OneToOne(targetEntity="B", mappedBy="a")
     */
    private $b;
}

/** 
 * @Entity 
 * @InheritanceType("SINGLE_TABLE")
 */
class B
{
    /**
     * @Id @Column(name="id", type="integer", nullable=false)
     */
    private $id;

    /**
     * @OneToOne(targetEntity="A", inversedBy="b")
     */
    private $a;
}

/** 
 * @Entity 
 */
class B_sub extends B
{
    /** @Column(type="string") */
    private $sub;
}

/** 
 * @Entity 
 */
class B_sub2 extends B
{
    /** @Column(type="string") */
    private $sub2;
}

The code creates several tables and a UNIQUE KEY constraint on B (a_id)

Now trying to accomplish the following sequence of action:

$B = new B_sub();
$A = new A();

$A->set('b', $B);
$B->set('a', $A);

$em->persist($A);
$em->persist($B);
//works fine and creates the correct DB entries
$em->flush();

$B_new = new B_sub2();
$B_old = $A->get('b');
$A->set('b', $B_new);
$B_new->set('a', $A);

$em->remove($B_old);
$em->persist($A);
$em->persist($B_new);
//does not work, because B_new is inserted first and fails the UNIQUE KEY constraint (both B_new and B_old refer to A)
$em->flush();

The result is a "Duplicate entry '1' for key 'UNIQ_7F6BFCEBE26CCE03'"



 Comments   
Comment by Philipp Dobrigkeit [ 10/Aug/12 ]

Current workaround is to change the ownership of the relationship

<?php

/** @Entity */
class A
{
    /**
     * @Id @Column(name="id", type="integer")
     */
    private $id;

    /**
     * @OneToOne(targetEntity="B", inversedBy="a")
     */
    private $b;
}

/** 
 * @Entity 
 * @InheritanceType("SINGLE_TABLE")
 */
class B
{
    /**
     * @Id @Column(name="id", type="integer", nullable=false)
     */
    private $id;

    /**
     * @OneToOne(targetEntity="A", mappedBy="b")
     */
    private $a;
}
Comment by Benjamin Eberlei [ 29/Aug/12 ]

Insert before Removal is by design, see discussion here http://www.doctrine-project.org/jira/browse/DDC-601





[DDC-1968] CommitOrderCalculator fails to calculate right order for mixing one-to-many and one-to-one relations Created: 05/Aug/12  Updated: 06/Jan/13  Resolved: 06/Jan/13

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

Type: Bug Priority: Major
Reporter: miptpatriot Assignee: Benjamin Eberlei
Resolution: Invalid Votes: 1
Labels: commitorder


 Description   

I have 2 classes. Zone and Rotator.
Zone relates to Rotator as One-to-Many. And Zone COULD realte to Rotator as One-to-One. Here is code snippet:

 
class Zone
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\OneToMany(targetEntity="Rotator", mappedBy="zone", cascade={"persist", "remove", "merge"}, orphanRemoval=true)
     * @ORM\OrderBy({"id" = "ASC"})
     */
    private $rotators = array();

    /**
     * @var Rotator $mainRotator
     *
     * @ORM\OneToOne(targetEntity="Rotator")
     * @ORM\JoinColumn(name="mainRotatorId", referencedColumnName="id")
     */
    private $mainRotator;

    /**
     * @var int $mainRotatorId
     *
     * @ORM\Column(name="mainRotatorId", type="integer", nullable="true")
     */
    private $mainRotatorId;
}
 
class Rotator
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var Zone $zone
     *
     * @ORM\ManyToOne(targetEntity="Zone")
     * @ORM\JoinColumn(name="zoneId", referencedColumnName="id")
     */
    private $zone;

    /**
     * @var int $zoneId
     *
     * @ORM\Column(name="zoneId", type="integer")
     */
    private $zoneId;
}

When I delete only Zone - calculator works fine. But it fails if I delete entity Site, that relates to Zone as one-to-many (and have a lot of other raltions, so I don't write it here).

As I look through the code, I see CommitOrderCalculator doesn't distiguish mandatory many-to-one relation from optional one-to-one one.

PS this code hadn't been changed since 2.0, so this bug should be reproducable for master.



 Comments   
Comment by Guilherme Blanco [ 17/Aug/12 ]

Your issue is because you have $zone and $zoneId pointing both to an association AND to a field.
Remove the $zoneId field (you can grab it by many different ways) and your issue should be solved.

Comment by Benjamin Eberlei [ 06/Oct/12 ]

You mention Site? Where is this entity, please make a snippet available as well.

And then, can you show some example object graph that you are trying to delete? This case is data dependent.

Comment by miptpatriot [ 06/Oct/12 ]
class Site
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var \Doctrine\Common\Collections\Collection|SiteAlias[]
     * @ORM\OneToMany(targetEntity="SiteAlias", mappedBy="site", cascade={"persist", "remove", "merge"}, orphanRemoval=true)
     */
    private $aliases;

    /**
     * @ORM\OneToMany(targetEntity="Zone", mappedBy="site", cascade={"persist", "remove", "merge"}, orphanRemoval=true)
     */
    private $zones;

    /**
     * @ORM\OneToMany(targetEntity="Banner", mappedBy="site", cascade={"persist", "remove", "merge"}, orphanRemoval=true)
     */
    private $banners;

    /**
     * @var integer
     *
     * @ORM\Column(name="user_id", type="integer")
     */
    private $user_id;

    /**
     * @var \Iw\UserBundle\Entity\User
     *
     * @ORM\ManyToOne(targetEntity="\Iw\UserBundle\Entity\User")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     */
    private $user;
}
Comment by miptpatriot [ 06/Oct/12 ]

Is there any fast way to debug output object graph? Like execute print_r somewhere in code.

Comment by Ivan Borzenkov [ 08/Nov/12 ]

Confirmed
removing ID fields not work

i fix this whis add

  • @ORM\JoinColumn(onDelete="cascade")
    to child Entity ManyToOne link

OnetoOne Unidirectinal set child after of parent
but OneToMany set set child before of parent (how need)

Comment by Benjamin Eberlei [ 06/Jan/13 ]

I finally get this issue, and bidirecitonal foreign keys are only deletable with "onDelete=CASCADE", there is absolutely no way for the CommitOrderCalculator to fix this.





Generated at Fri Nov 28 21:58:14 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.