Orm ZF2-更新实体中的字段

Orm ZF2-更新实体中的字段,orm,doctrine,zend-framework2,Orm,Doctrine,Zend Framework2,我目前拥有以下数据库结构: table: user fields: user_id, name, id 我从一个教程中获得了以下实体,它工作得非常完美: <?php namespace Administration\Entity; use Doctrine\ORM\Mapping as ORM; /** @ORM\Entity */ class User { /** * @ORM\id * @ORM\

我目前拥有以下数据库结构:

table: user
fields: user_id, name, id
我从一个教程中获得了以下实体,它工作得非常完美:

<?php
    namespace Administration\Entity;
    use Doctrine\ORM\Mapping as ORM;

    /** @ORM\Entity */

    class User {
        /**
         * @ORM\id
         * @ORM\GeneratedValue(strategy="AUTO")
         * @ORM\Column(type="integer")
         */
        protected $id;

        /** @ORM\Column(type="string", name="name") */
        protected $name;

        public function setName($name) {
            $this->name = $name;
        }

        public function getName() {
            return $this->name;
        }
    }
很明显,错误表明user_id属性不存在,但我不理解为什么会出现这种情况

当我删除字段并重新添加它时,我会得到相同的错误

如果我在实体中添加id作为主字段,添加user_id作为另一个字段,则不会抛出错误


是否所有主字段都应该被称为id,而ZF2期望这样做???

我发现,基本上,@ORM\id标识的是主键,而不是字段名:id

这让人有点困惑

<?php
    namespace Administration\Entity;
    use Doctrine\ORM\Mapping as ORM;

    /** @ORM\Entity */

    class User {
        /**
         * @ORM\user_id
         * @ORM\GeneratedValue(strategy="AUTO")
         * @ORM\Column(type="integer")
         */
        protected $user_id;

        /** @ORM\Column(type="string", name="name") */
        protected $name;

        public function setName($name) {
            $this->name = $name;
        }

        public function getName() {
            return $this->name;
        }
    }
 Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message '[Semantical Error] The annotation "@Doctrine\ORM\Mapping\user_id" in property Administration\Entity\User::$user_id does not exist, or could not be auto-loaded.' in /trunk/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php on line 52