DDC-588: EntityManager::refresh fails when ID columnName differs from fieldName #722

Open
opened 2026-01-22 12:48:04 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (May 14, 2010).

Jira issue originally created by user @hobodave:

Reproduce:

/****
 * @Entity
 * @Table(name="site")
 */
class Site
{
    /****
     * @Id
     * @Column(type="integer", name="site_id")
     * @GeneratedValue
     */
    protected $id;

    /*** @Column(type="string",length=45, unique=true) **/
    protected $name;

    public function **construct($name = '')
    {
        $this->name = $name;
    }
}

$site = new Site('Foo');
$em->persist($site);
$em->flush();
$em->refresh($site);

Result:

Doctrine\ORM\ORMException: Unrecognized field: site_id

/Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/ORMException.php:45
/Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:1042
/Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:783
/Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:571
/Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/UnitOfWork.php:1485
/Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/UnitOfWork.php:1461
/Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/EntityManager.php:431
/Users/hobodave/dev/work/S5/tests/application/modules/common/services/SiteServiceTest.php:69
Originally created by @doctrinebot on GitHub (May 14, 2010). Jira issue originally created by user @hobodave: Reproduce: ``` /**** * @Entity * @Table(name="site") */ class Site { /**** * @Id * @Column(type="integer", name="site_id") * @GeneratedValue */ protected $id; /*** @Column(type="string",length=45, unique=true) **/ protected $name; public function **construct($name = '') { $this->name = $name; } } $site = new Site('Foo'); $em->persist($site); $em->flush(); $em->refresh($site); ``` Result: ``` Doctrine\ORM\ORMException: Unrecognized field: site_id /Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/ORMException.php:45 /Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:1042 /Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:783 /Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:571 /Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/UnitOfWork.php:1485 /Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/UnitOfWork.php:1461 /Users/hobodave/dev/work/doctrine2/lib/Doctrine/ORM/EntityManager.php:431 /Users/hobodave/dev/work/S5/tests/application/modules/common/services/SiteServiceTest.php:69 ```
admin added the Bug label 2026-01-22 12:48:04 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#722