• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Entity Listener within relations

Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • 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.
    Bookmark Topic Watch Topic
  • New Topic