I’d like to override a setter so that I can perform some function on the data so I can return a calculated column for my entity. The function depends a several columns (e.g. COL1, COL2, …) so I can’t really intercept any particular setter because the other values might not yet be populated. Does hibernate provide some sort of “finish()” method that can be called once at the values are set for the Entity?
@Override
@Column(name="COL1")
public String getCol1() {
return this.col1;
}
@Override
public void setCol1(String value) {
super.setCol1(value);
genMagicValue();
}
public String getMagicValue() {
return this.magicValue();
}
I don’t understand your question,
setCol1 may be never called (and left with its default value).
Furthermore, no one is preventing you to call it twice with different values.
perhaps the pattern you are looking for is: