我有两个学说实体:
Commessa
/**
* @ORM\Id
* @ORM\Column(type = "bigint")
* @ORM\GeneratedValue(strategy = "AUTO")
*/
private $id;
/* ... */
/*
* @ORM\OneToMany(targetEntity = "AppBundle\Entity\Pipeline\pipeline", mappedBy = "commessa", cascade = {"persist", "remove"})
*/
private $pipelines;
和管道
/**
* @ORM\Id
* @ORM\Column(type = "bigint")
* @ORM\GeneratedValue(strategy = "AUTO")
*/
private $id;
/* ... */
/**
* @ORM\ManyToOne(targetEntity = "AppBundle\Entity\Commessa\commessa", inversedBy = "pipelines")
* @ORM\JoinColumn(name = "id_commessa", name = "id")
*/
private $commessa;
如您所见,两个实体都有一个AUTO-INCREMENT,一个名为id的单字段主键,以及另一个实体的双向关联;每当我使用commessa时,管道就会自动保留 此外,两个实体只有id的getter方法,而不是setter方法。
现在,每当我尝试刷新Commessa类的对象实例(包括多个管道)时,会弹出以下错误:
使用params [“”,“frontend”,“9”]执行'INSERT INTO管道(descrizione,nome_logico,id)VALUES(?,?,?)'时发生异常:
SQLSTATE [23000]:完整性约束违规:1062密钥'PRIMARY'的重复条目'9'
在我的代码中没有任何一点我设置了管道的id,并且在刷新之前(并且在持久化之后)转储Commessa对象显示它已正确填充,并且管道具有“null”作为id,我猜是正确的。
通过Symfony分析器,报告以下查询:
"START_TRANSACTION"
INSERT INTO commessa (codice_commessa, data_creazione, data_scadenza, descrizione, id_anagrafica, id_cliente, id_stato, id_tipo_commesa) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
Parameters: [ 1 => lyme, 2 => 2017-01-13 10:47:53, 3 => 2017-01-17 00:00:00, 4 => Fai Lyme, 5 => 1, 6 => 1, 7 => 1, 8 => 1 ]
INSERT INTO pipeline (descrizione, nome_logico, id) VALUES (?, ?, ?)
Parameters: [1 => , 2 => frontend, 3 => 10]
INSERT INTO pipeline (descrizione, nome_logico, id) VALUES (?, ?, ?)
Parameters: [1 => , 2 => backend, 3 => 10]
"ROLLBACK"
然后我偶然发现了the doctrine limitations and known issues page,并指出了第28.1.3点
现在有两个错误涉及级联合并与双向关联的结合使用。 但是相关的票证链接已经死了。
这可能是我的问题吗? 如果是,我该如何解决这个问题?
答案 0 :(得分:0)
@ORM \ JoinColumn(name =“id_commessa”,name =“id”)错误。名称字段有2次