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

标签 hibernate hibernate-onetomany

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

相关文章:

java - 数据库连接错误

java - list() 返回什么类型的列表?

java - 不要更改对具有级联 ="all-delete-orphan"的集合的引用

java - ManyToOne OneToMany 双向 : Retrieve data from reference table

java - 创建名称为 'mvcValidator' 的 bean 时出错

java - Hibernate @AttributeOverride 导致将属性设置为@Transient

hibernate - 陈旧状态异常 : Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

java - Hibernate 为 OneToMany 集合检索 null

java - 无法在 HIbernate 4 中保留 OneToMany 关系

java - 在没有无限递归的情况下将 @OneToMany 关系与 @RestController 结合使用的最佳实践是什么