本文介绍了JPA.@ManyToOne 相关字段上的 @Column(updatable=false)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的可审计实体中,我有字段 creationUser
,我不想在 merge
操作时在 db 中更新该字段.
In my auditable entities I have field creationUser
which I would like to not update in db on merge
operation.
这是我的实体代码:
@Column(updatable=false)
@ManyToOne(cascade = CascadeType.MERGE)
public User creationUser;
但它给了我一个错误:
Unexpected exception
PersistenceException: [PersistenceUnit: defaultPersistenceUnit] Unable to build EntityManagerFactory
Caused by: org.hibernate.AnnotationException: @Column(s) not allowed on a @ManyToOne property: models.AreaOfMedicine.creationUser
那么如何防止更新该字段?请帮忙
So how can I prevent from updating that field?Please help
推荐答案
使用 @JoinColumn(updatable = false)
而不是 @Column(updatable = false)
.
这篇关于JPA.@ManyToOne 相关字段上的 @Column(updatable=false)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!