From 600af3e617e511a8fe843cba22357beec519e104 Mon Sep 17 00:00:00 2001 From: Aaron Muylaert Date: Sat, 14 Dec 2013 13:24:47 +0100 Subject: [PATCH 1/2] Add failing test for DDC-1787. Using joined table inheritance, when persisting multiple new entities that are subclasses of a baseclass that has the @Version attribute set, only the last persisted entity will have it's version set. --- .../ORM/Functional/Ticket/DDC1787Test.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php new file mode 100644 index 00000000000..9e3037bed5c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php @@ -0,0 +1,63 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1787Foo'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1787Bar'), + )); + } + + public function testIssue() + { + $bar = new DDC1787Bar; + $bar2 = new DDC1787Bar; + + $this->_em->persist($bar); + $this->_em->persist($bar2); + $this->_em->flush(); + + $this->assertSame(1, $bar->getVersion()); + } +} + +/** + * @Entity + * @InheritanceType("JOINED") + * @DiscriminatorColumn(name="discr", type="string") + * @DiscriminatorMap({"bar" = "DDC1787Bar"}) + */ +class DDC1787Foo +{ + /** + * @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * @Version @Column(type="integer") + */ + private $version; + + public function getVersion() + { + return $this->version; + } +} + +/** + * @Entity + */ +class DDC1787Bar extends DDC1787Foo +{ +} From 3cc630798b630f66eafe940a9eee7521f1bd9a6e Mon Sep 17 00:00:00 2001 From: Aaron Muylaert Date: Sat, 14 Dec 2013 13:50:46 +0100 Subject: [PATCH 2/2] Fix DDC-1787. Credit goes to Jack van Galen for fixing this issue. Fix for JoinedSubclassPersister, multiple inserts with versioning throws an optimistic locking exception. --- lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 684d30571cc..1fce9c701fd 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -181,6 +181,10 @@ public function executeInserts() $id = $this->em->getUnitOfWork()->getEntityIdentifier($entity); } + if ($this->class->isVersioned) { + $this->assignDefaultVersionValue($entity, $id); + } + // Execute inserts on subtables. // The order doesn't matter because all child tables link to the root table via FK. foreach ($subTableStmts as $tableName => $stmt) { @@ -212,10 +216,6 @@ public function executeInserts() $stmt->closeCursor(); } - if ($this->class->isVersioned) { - $this->assignDefaultVersionValue($entity, $id); - } - $this->queuedInserts = array(); return $postInsertIds;