JPA. @Column(updatable=false) on @ManyToOne related field

[亡魂溺海] 提交于 2019-12-24 03:36:24

问题


In my auditable entities I have field creationUser which I would like to not update in db on merge operation.

Here is my entity code:

@Column(updatable=false) 
@ManyToOne(cascade = CascadeType.MERGE)
public User creationUser;

But it gives me an error:

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


回答1:


Use @JoinColumn(updatable = false) instead of @Column(updatable = false).



来源:https://stackoverflow.com/questions/29917148/jpa-columnupdatable-false-on-manytoone-related-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!