0
学说2实体的实体具有复合键:学说2 - 持续复合键
/**
* @Entity
*/
class Test
{
/**
* @Id
* @Column (type="integer", length=11, name="id")
*
*/
protected $id = null;
/**
* @Id
* @Column (type="integer", length=11, name="idtwo")
*
*/
protected $idtwo = null;
public function setIdTwo($id)
{
$this->idtwo = $id;
}
public function setId($id)
{
$this->id = $id;
}
}
保存实体
$test = new Test();
$test->setId(1);
$test->setIdTwo(1);
$em->persist($test);
DB表:
CREATE TABLE `Bella_Test` (
`id` int(11) NOT NULL,
`idtwo` int(11) NOT NULL,
PRIMARY KEY (`id`,`idtwo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
预期结果:将一行添加到带有两个ID字段的数据库表中,其值为1.
实际结果:没有行被添加到数据库表中。没有例外被抛出。
问题:发生了什么事?
你叫'$ EM->的flush()' – rojoca 2011-04-18 02:49:09
使用复合材料的PK,确保他们的工作在理论上很好,但你有没有尝试过删除从来不喜欢或更新一个?该应用程序需要知道这两个值,而不是一个PK,应用程序只需要知道一个ID。 – 2011-12-01 01:00:10