In our base entity class (that all entities derive from), we have, amongst others, 2 methods. One annotatted with @PrePersist
which basically just sets the dateCreated
, and the other annotated with @PreUpdate
which sets the dateUpdated
field.
This works perfectly, as we do not wish to set the dateUpdated
field on creation. As part of the design, we also make the two methods protected
so that other developers don't go and explicitly mess with those two dates (also no setters).
Also, we can easily enough extend any entity to set the dateUpdated
field on creation by defining a method on the actual entity and also annotate it with @PrePersist
, so this part is covered.
Now, my problem at the moment is that there is a case where we would like to explicitly update the dateUpdated
field on an entity, without any data on it changing (basically touch
it). Is there an elegant way of doing this? I do not really want to implement a method that changes one of it's fields and then change it back. And we would like to keep having the entities without setter methods for those fields.
Thanks!