问题
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