1

XMLフィードからエンティティを逆シリアル化しています。エンティティにはすでにIDがあります(XMLからの読み取り)。

エンティティを永続化してフラッシュする(データベースに保存する)前に、エンティティをマージしようとしています。エンティティがデータベースにすでに存在している可能性があるため、エンティティをマージする必要があります。その場合、検証に失敗するのではなく、更新する必要があります。

これが私のコードです:

<?php

// build the MgLeague from xml
$league = $this->serializer->deserialize(
    $xml, 
    'Acme\Website\Entity\MgLeague',
    'xml'
);

if ($league)
{
    // merge the league
    $league = $this->em->merge($league);

    // validate
    if (0 === count($this->validator->validate($league)))
    {
        $this->em->persist($league);
        $this->em->flush();
    }
}

そして、これが私が受け取っているエラーです:

PHP Fatal error:  Call to undefined method Doctrine\ORM\UnitOfWork::newInstance() in /Website/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php on line 1457
PHP Stack trace:
PHP   1. {main}() /Website/app/console:0
PHP   2. Symfony\Component\Console\Application->run() /Website/app/console:22
PHP   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /Website/vendor/symfony/src/Symfony/Component/Console/Application.php:118
PHP   4. Symfony\Component\Console\Application->doRun() /Website/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:75
PHP   5. Symfony\Component\Console\Command\Command->run() /Website/vendor/symfony/src/Symfony/Component/Console/Application.php:194
PHP   6. Mahango\WebServiceBundle\Command\InsertLeaguesCommand->execute() /Website/vendor/symfony/src/Symfony/Component/Console/Command/Command.php:224
PHP   7. Doctrine\ORM\EntityManager->merge() /Website/src/Mahango/WebServiceBundle/Command/InsertLeaguesCommand.php:131
PHP   8. Doctrine\ORM\UnitOfWork->merge() /Website/vendor/doctrine/lib/Doctrine/ORM/EntityManager.php:531
PHP   9. Doctrine\ORM\UnitOfWork->doMerge() /Website/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php:1378

Fatal error: Call to undefined method Doctrine\ORM\UnitOfWork::newInstance() in /Website/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php on line 1457

Call Stack:
    0.0003     632280   1. {main}() /Website/app/console:0
    0.0133    2936544   2. Symfony\Component\Console\Application->run() /Website/app/console:22
    0.0151    3192136   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /Website/vendor/symfony/src/Symfony/Component/Console/Application.php:118
    0.0538    7941912   4. Symfony\Component\Console\Application->doRun() /Website/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:75
    0.0552    7941912   5. Symfony\Component\Console\Command\Command->run() /Website/vendor/symfony/src/Symfony/Component/Console/Application.php:194
    0.0816   13131288   6. Mahango\WebServiceBundle\Command\InsertLeaguesCommand->execute() /Website/vendor/symfony/src/Symfony/Component/Console/Command/Command.php:224
    0.4149   13519208   7. Doctrine\ORM\EntityManager->merge() /Website/src/Mahango/WebServiceBundle/Command/InsertLeaguesCommand.php:131
    0.4149   13519208   8. Doctrine\ORM\UnitOfWork->merge() /Website/vendor/doctrine/lib/Doctrine/ORM/EntityManager.php:531
    0.4149   13519424   9. Doctrine\ORM\UnitOfWork->doMerge() /Website/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php:1378

私にはDoctrineのバグのように見えます。

Doctrine(バージョン2.1.6)でSymfony2(バージョン2.0.12)を使用しています。

4

1 に答える 1

1

はい、これは教義のバグです。バグレポートは次のとおりです。

http://www.doctrine-project.org/jira/browse/DDC-1638

..そしてここに修正があります:

https://github.com/doctrine/doctrine2/commit/affa6feb8aa207bf74406a4dd20adad6978f0f1e#diff-0

于 2012-04-29T19:24:02.383 に答える