我对 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/