I try to put the domain logic within the domain and as a tool I try to use JPA entity listeners. By using this I encountered some strange behaviour.
When I use a Entity by updating the relations between some Entities the @PreUpdate and @PrePersist annotated procedures are called. I just want to call them when I do a direct update on the Entity and not when this entity is used by setting a relation between Entities. When an entity is set within a relation the contents of the entity itself is not changed.
Why then are the procedures called? Within JPA there is no standaard way to see the difference between the calls. Is this true?
Now I've solved this within the form by disabling some buttons But it's my believe that this logic should be coded within the Entity itself.
A solution could be by coding some rules within the setter of the entity
A another solution is checking if the entity has changed. Is there some standard function for this? Until now I haven't discovered one.