5

I am using EntityListeners (@PreUpdate) to perform certain actions once my entities change. However I noticed that changes of a collection inside an entity does not fire the JPA entity listener, that makes sense because the table containing the entity was not changed, but a many to many table was.

Is there a way to make the entity listener fire in case of a collection change?

Noam Nevo
  • 3,021
  • 10
  • 35
  • 49
  • Why don't you place the PreUpdate attribute in the child Entity instead of the parent? – perissf Feb 29 '12 at 15:49
  • @perissf the table that is being updated is a many to many table that is not mapped as an entity in my code. – Noam Nevo Feb 29 '12 at 15:53
  • Hi, I noticed the same behaviour using JPA/Hibernate. It is a problem for me since auditing, which is triggered by an EntityListener, does not take place if for example I add a role to a user (many-to-many collection). Did you find a way to workaround this ? – Pierre Henry Jun 12 '13 at 10:07

2 Answers2

3

Listeners are fired for versioned entities (see javax.persistence.Version). Found via this answer: https://stackoverflow.com/a/17073342/12039

Community
  • 1
  • 1
Kariem
  • 4,398
  • 3
  • 44
  • 73
0

I would expect the events to be called. What JPA provider are you using?

James
  • 17,965
  • 11
  • 91
  • 146