完整性约束违规:多对一 - 级联所有

时间:2013-10-28 12:36:18

标签: hibernate jpa cascade many-to-one

我是hibernate和JPA的新手,我正在尝试做下一件事:

public class Centre extends JpaStandardVersionableEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "sq")
@SequenceGenerator(name = "sq", sequenceName = SQ_NAME)
@Column(name = "ID_CTR", nullable = false)
private Integer idCtr;
        ...

@JoinColumn(name = "ID_DRC", referencedColumnName = "ID_DRC", nullable = false)
@ManyToOne(cascade = CascadeType.ALL, optional = false, fetch = FetchType.LAZY)
private Address idDrc;

}


public class Address extends JpaStandardVersionableEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "sq")
@SequenceGenerator(name = "sq", sequenceName = SQ_NAME)
@Column(name = "ID_DRC", nullable = false)
private Integer idDrc;
}

使用级联ALL以便在我注册中心时插入地址。

但我遇到此错误:违反了完整性约束FK_CTR_DRC - 未找到父密钥

似乎这没有按预期工作......任何想法?提前致谢

1 个答案:

答案 0 :(得分:0)

该片段是正确的。我的问题实际上与地址触发器有关。为不便而道歉。