Spring Data JPA:不保留父关系列映射

时间:2019-06-17 12:14:06

标签: spring spring-boot spring-data-jpa one-to-many

目前,我正在遵循URL,并在结尾处实现了类似的代码。

但这同样给我一个错误,

null value in column "file_id" violates not-null constraint

在这里,category_id是我的parent_entities主键之一。

以下是我正确传递父实体并通过Debug检查的行

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,这些只是我针对this article.所做的更改

0 个答案:

没有答案