diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 6af159fc7..972199c5e 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -344,13 +344,30 @@ class BasicEntityPersister implements EntityPersister . ' FROM ' . $tableName . ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; + $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); - $value = $this->conn->fetchColumn($sql, array_values($flatId)); + $value = $this->conn->fetchColumn( + $sql, + array_values($flatId), + 0, + $this->extractIdentifierTypes($id, $versionedClass) + ); return Type::getType($fieldMapping['type'])->convertToPHPValue($value, $this->platform); } + private function extractIdentifierTypes(array $id, ClassMetadata $versionedClass) : array + { + $types = []; + + foreach ($id as $field => $value) { + $types = array_merge($types, $this->getTypes($field, $value, $versionedClass)); + } + + return $types; + } + /** * {@inheritdoc} */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php new file mode 100644 index 000000000..77d4fbc87 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php @@ -0,0 +1,108 @@ +_schemaTool->createSchema( + [$this->_em->getClassMetadata(GH5804Article::class)] + ); + } + + public function testTextColumnSaveAndRetrieve2() + { + $firstArticle = new GH5804Article; + $firstArticle->text = 'Max'; + $this->_em->persist($firstArticle); + $this->_em->flush(); + + self::assertSame(1, $firstArticle->version); + + $firstArticle->text = 'Moritz'; + $this->_em->persist($firstArticle); + $this->_em->flush(); + + self::assertSame(2, $firstArticle->version); + } +} + +final class GH5804Generator extends AbstractIdGenerator +{ + /** + * {@inheritdoc} + */ + public function generate(EntityManager $em, $entity) + { + return 'test5804'; + } +} + +final class GH5804Type extends Type +{ + const NAME = 'GH5804Type'; + + public function getName() + { + return self::NAME; + } + + /** + * {@inheritdoc} + */ + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + { + return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); + } + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + if (empty($value)) { + return null; + } + + return 'testGh5804DbValue'; + } +} + +/** + * @Entity + */ +class GH5804Article +{ + /** + * @Id + * @Column(type="GH5804Type") + * @GeneratedValue(strategy="CUSTOM") + * @CustomIdGenerator(class=\Doctrine\Tests\ORM\Functional\Ticket\GH5804Generator::class) + */ + public $id; + + /** + * @Version + * @Column(type="integer") + */ + public $version; + + /** + * @Column(type="text") + */ + public $text; +}