Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Hibernate to not update certain columns

I have an application that will give a user an opportunity to update certain values. I want to send just the info on those columns to the user and take updates.

I'd like to persist a hibernate entity created from what they send to me, but not update the columns that the user does not have access to. Likewise, if they request a new entry, I want to use the data they send me and set the unmentioned columns to the databases defaults.

Is there an easy way or best practice to use?

Should I create a second mapping to the table that just doesn't mention those columns?

like image 900
Joe Avatar asked Nov 11 '11 17:11

Joe


2 Answers

I think I will mark the property update="false" on the mapping file. I'd love to hear if there is a way to do it per persist, so if I wrote something else that should change those fields, it could do it.

like image 57
Joe Avatar answered Sep 27 '22 20:09

Joe


Use updatable=false in Hibernate to avoid updating the column.

Eg:

@Column(name=CRE_TS, updatable=false)
private Date getCreTs(){
   return this.creTs;
} 
like image 44
Kisanagaram Avatar answered Sep 27 '22 21:09

Kisanagaram