Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Entity Listener within relations

Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!