I need an @PreUpdate method to be called when an @Transient attribute is modified. This @Transient will always be modified, so yes @PreUpdate would always have to be called. Since it will always have to be called, I looked for an option similar to @PreUpdate, but it was called regardless of whether it has changed attributes or not, as it is this method that will set the value of a column to be persisted, according to the value no @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;
In this way, the "transient" will always be loaded with the column value that it will possibly change. If this "transient" is changed, it will fall into @PreUpdate and perform some operations that will define whether the value it holds will be passed to the original attribute be persisted.
The question is: What problems can this approach bring?
And is there any alternative to this value "transient" ?
Better yet, is there an alternative to @PreUpdate, so that the method is called at the last possible moment, regardless of whether there are changes so far to be persisted, so that it only performs the verification of the modified attributes after this method? / p>