Zend2 Framework - Doctrine ORM giving Mapping Exception
我正在为我的Zend2应用程序之一使用Doctrine 2 ORM。我在Composer的帮助下使用Doctrine模块在应用程序中进行了设置。
我能够将数据持久保存到数据库中,但是当我在对象管理器上进行find()调用时,它会给我一个映射异常,并显示以下消息。
1 2 3 4 5 | Doctrine\\Common\\Persistence\\Mapping\\MappingException File: /vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:96 Message: Class 'User' does not exist |
以下是在"应用程序"模块配置文件下添加的"教义"设置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 'driver' => array( 'application_entities' => array( 'class' =>'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver', 'cache' => 'array', 'paths' => array(__DIR__ . '/../src/Application/Entity') ), 'orm_default' => array( 'drivers' => array( 'Application\\Entity' => 'application_entities' ) ) ) ), |
这是在Application \\\\\\\\ src \\\\\\\\ Entity文件夹下创建的用户实体
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | <?php namespace Application\\Entity; use Doctrine\\ORM\\Mapping as ORM; /** * @ORM\\Entity */ class User { /** * @ORM\\Id * @ORM\\Column(type="integer") * @ORM\\GeneratedValue(strategy="NONE") * @var int */ protected $user_id; /** * @ORM\\Column(type="integer") * @var int */ protected $network_id; /** * @ORM\\Column(type="string", length=64) * @var string */ protected $network_name; /** * @ORM\\Column(type="string", length=64) * @var string */ protected $job_title; /** * @ORM\\Column(type="string", length=64) * @var string */ protected $location; /** * @ORM\\Column(type="string", length=64) * @var string */ protected $first_name; /** * @ORM\\Column(type="string", length=64) * @var string */ protected $last_name; /** * @ORM\\Column(type="string", length=255) * @var string */ protected $url; /** * @ORM\\Column(type="string", length=255) * @var string */ protected $img_url; /** * @ORM\\Column(type="string", length=255) * @var string */ protected $department; /** * @ORM\\Column(type="string", length=255) * @var string */ protected $email_address; /** * @ORM\\Column(type="boolean") * @var string */ protected $verified; /** * @return the int */ public function getUserId() { return $this->user_id; } /** * @param int $user_id */ public function setUserId($user_id) { $this->user_id = $user_id; return $this; } /** * @return the int */ public function getNetworkId() { return $this->network_id; } /** * @param int $network_id */ public function setNetworkId($network_id) { $this->network_id = $network_id; return $this; } /** * @return the string */ public function getNetworkName() { return $this->network_name; } /** * @param string $network_name */ public function setNetworkName($network_name) { $this->network_name = $network_name; return $this; } /** * @return the string */ public function getJobTitle() { return $this->job_title; } /** * @param string $job_title */ public function setJobTitle($job_title) { $this->job_title = $job_title; return $this; } /** * @return the string */ public function getLocation() { return $this->location; } /** * @param string $location */ public function setLocation($location) { $this->location = $location; return $this; } /** * @return the string */ public function getFirstName() { return $this->first_name; } /** * @param string $first_name */ public function setFirstName($first_name) { $this->first_name = $first_name; return $this; } /** * @return the string */ public function getLastName() { return $this->last_name; } /** * @param string $last_name */ public function setLastName($last_name) { $this->last_name = $last_name; return $this; } /** * @return the string */ public function getUrl() { return $this->url; } /** * @param string $url */ public function setUrl($url) { $this->url = $url; return $this; } /** * @return the string */ public function getImgUrl() { return $this->img_url; } /** * @param string $img_url */ public function setImgUrl($img_url) { $this->img_url = $img_url; return $this; } /** * @return the string */ public function getDepartment() { return $this->department; } /** * @param string $department */ public function setDepartment($department) { $this->department = $department; return $this; } /** * @return the string */ public function getEmailAddress() { return $this->email_address; } /** * @param string $email_address */ public function setEmailAddress($email_address) { $this->email_address = $email_address; return $this; } /** * @return the boolean */ public function getVerified() { return $this->verified; } /** * @param boolean $verified */ public function setVerified($verfied) { $this->verified = $verfied; return $this; } |
} ??
现在,当我从应用程序模块的IndexController对上述实体进行持久化操作时,它可以正常工作。但是当我在同一IndexController中使用同一对象映射器执行find操作时,它给出了映射异常。
以下是我的操作方式:
1 2 3 4 | $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $objectManager->persist($user); $objectManager->flush(); $user = $objectManager->find('User', $uniqueID); |
有人可以帮我解决这个问题吗?
致谢。
您的实体不是
1 | $user = $objectManager->find('User', $uniqueID); |
与此:
1 | $user = $objectManager->find('Application\\Entity\\User', $uniqueID); |