spring - Spring Data JPA:不持久化父关系列映射
问题描述
目前我正在关注这个URL 并在最后实现了类似的代码。
但它在我的最后也给出了一个错误,
null value in column "file_id" violates not-null constraint
在这里, category_id 是我的 parent_entities 主键之一。
遵循我正确传递父实体并通过调试检查的行,
EntityManager entityManager = BeanUtil.getBean(EntityManager.class);
entityManager.persist(new FileHistory(target, action));
更新 -
在这里,而不是以下配置,
@ManyToOne
@JoinColumn(name = "file_id", foreignKey = @ForeignKey(name = "FK_file_history_file"))
我用过,
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "file_id")
另外,我使用@PostPersist
的不是@PrePersist
这些,而是我对本文所做的更改。