gpt4 book ai didi

hibernate - org.hibernate.AssertionFailure : null identifier with OneToMany/ManyToOne Relationship

转载 作者:行者123 更新时间:2023-12-02 23:12:00 27 4
gpt4 key购买 nike

我对 OneToMany/ManyToOne 关系有疑问:

类项目:

@OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.ALL,
orphanRemoval=true )
@JoinColumn(name="PROJECT_ID", nullable=true)
private Set<Person> personlist = new HashSet<Person>();

类(class)人员:

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "PROJECT_ID")
private Project project;

只要至少有一个人连接到数据库中的项目,一切都会正常工作。如果我创建一个新项目并且数据库中没有人员,我会收到一个 hibernate 异常:

org.hibernate.AssertionFailure: null identifier

我已经为项目类设置了 nullable=true 但这不起作用。有人有想法吗?

最佳答案

不确定这是否有帮助尝试@ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL,Optional = true)

关于hibernate - org.hibernate.AssertionFailure : null identifier with OneToMany/ManyToOne Relationship,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13950064/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com