且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么 hibernate 为 OneToMany 映射生成插入和更新

更新时间:2023-02-07 14:41:15

我知道这太老了,但我遇到了同样的问题,谷歌把我带到了这里,所以在修复它之后我想我应该发布一个答案.

I know this is crazy old but I had the same problem and Google brought me here, so after fixing it I figured I should post an answer.

如果您使连接列不可为空且不可更新,Hibernate 会将插入/更新方法切换为直接插入,我认为在您的情况下无论如何都不是:

Hibernate will switch the insert/update approach to straight inserts if you make the join column not nullable and not updatable, which I assume in your case it is neither anyways:

@JoinColumn(name = "PRODUCT_ID", nullable = false, updatable = false)