Thursday, April 19, 2012

hibernate: update a column based on another

i have a table with 2 main columns: name and name without accent.
i would like hibernate to update the 2nd one when 1st one is changed:



@Column(name = "name")
public String getName() {
return this.name;
}

public void setName(String s) {
this.name = s;
this.noAccentName = RemoveDiacritics(name); //remove diacritics from name
}

@Column(name = "noaccent_name")
public String getNoAccentName() {
return this.noAccentName;
}

public void setNoAccentName(String s) {
this.noAccentName = s;
}


This is working but it has an overhead: setter of the name sets object to dirty, and hibernate wants to update it all the time... :(



How can i ask hibernate to update 'noAccentName' when 'name' was changed in a clean way?



Thanks a lot,





No comments:

Post a Comment