在我的可审计实体中,我有一个字段creationUser
,我不想在合并
操作时在数据库中更新该字段。
这是我的实体代码:
@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
那么我怎样才能阻止更新该字段呢? 请帮忙
最佳答案
使用@JoinColumn(updatable = false)
而不是@Column(updatable = false)
。
关于hibernate - JPA。 @ManyToOne 相关字段上的 @Column(updatable=false),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29917148/