I am using JPA with Hibernate as an implementation in my Spring webapp.
I use EntityListenernotifications for audit (Spring-data) and other purposes. All in all, it works great. However, when making changes to the collection / many-to-many relationship without any changes in any field of the objects themselves, the event @PostUpdate EventListenerdoes not fire.
To give a specific example: I have a nature Userand Rolewith links to "many-to-many relationship" between them, using the base table. If I go to the user management GUI and add (or delete) roles for the user without changing anything else, the "postUpdate" event will not be fired, the audit information will not be changed.
There is some logic for it (at a low level), since neither the user nor the role tables are updated, only the relationship table. However, the relationship itself is not modeled as an entity class, and therefore it is impossible to apply an audit to it, at least not at the JPA level, so it would be advisable to trigger a change event for the entity itself.
Is this normal JPA behavior, or is it related to Hibernate? Is there any workaround? What would you do to trigger this event? Thoughts?
Note. I found very few references to this limitation and even fewer solutions:
This question is SO (without a useful answer) and this post on the Hibernate forum is also without any answer.
source
share