2
I need a @Preupdate method to be called when a @Transient attribute is modified. This @Transient will always be modified, so yes, @Preupdate would have to be called every time. Since it will always have to be called, I looked for an option similar to @Preupdate, but that was called regardless of whether it has modified attributes or not, because it is this method that will define the value of a column to be persisted, according to the value in @Transient. The alternative I found was to define the following attributes:
@Column(name="valor")
private Double valor;
@Column(name="valor", insertable=false, updatable=false)
private Double valorTransientDisfarcado;
Thus, the "Transient" will always be loaded with the column value that it will possibly change. Case that "Transient" be changed, it will fall into @Preupdate and perform some operations that will define whether the value it has will be transmitted to the attribute "original" to be persisted.
The question is: What problems can this approach bring?
And is there any alternative to that value "Transient"?
Better yet, there is some alternative to @Preupdate, so that the method is called at the last possible moment, regardless if there are changes, until now, to be persisted, so that it only performs the verification of the modified attributes after this method?
How would this attribute be @Transient you couldn’t put this @Preupdate logic into the Setter of that attribute? Thus, when the value of the Transient is changed (through the
setTransient()
) it can be validated and modify the other attributevalorTransientDisfarcado
– Andre Gusmao