【发布时间】:2011-05-03 13:53:53
【问题描述】:
我正在使用类表继承策略与 D2 实现继承映射。我有一个名为 Person 的父类,其代码块如下
namespace Zain\Entity;
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="Specialty", type="string") // what other types exist?
* @DiscriminatorMap({"person" = "\Zain\Person", "employee" = "\Staff\Entities\Employee"})
*
* @Table(name="db_One.tblPerson")
*
*/
class Person
{
...
我有一个名为 Employee 的子类,代码如下:
namespace Staff\Entities;
/**
* Description of Employee
* @Entity
* @Table(name="db_Two.tblEmployee")
*
*/
class Employee extends \Zain\Entity\Person
{
...
MySQL 表:tblPerson 有一个名为 Specialty 的鉴别器列,定义为:
`Specialty` varchar(45) NOT NULL
当我有一个 Employee 实例并尝试持久化它时,就会出现问题。
当 Employee 实例被持久化时,我希望对象名称、employee(字符串)将保存在表 Person 的 Specialty 列中。 然而,这并没有发生。我遇到错误消息:
Message: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'specialty' cannot be null
我了解此错误意味着没有为 EntityManager 生成和使用的 SQL 语句中的 Specialty 列传递任何值。我在 tblPerson > Specialty Column 上设置了 Not Null 约束。
如果我删除了非空约束,我可以让它工作——但这违背了目的。为了解决这个问题,您能否告诉我如何检索生成的 SQL 语句,该语句在持久调用期间由实体管理器使用/将使用?
很高兴能在几天的寻找答案中画上一个圆满的句号。再次感谢。
【问题讨论】:
标签: php orm doctrine-orm