JPA EventListener method not called on change to many-to-many collection?

后端 未结 1 1397
挽巷
挽巷 2020-12-06 20:22

I am using JPA with Hibernate as the implementation in my Spring webapp.

I use EntityListeners for auditing (Spring-data) and other notification purpose

相关标签:
1条回答
  • 2020-12-06 20:54

    The JPA spec is very unclear about changes to collections triggering pre/post update callbacks on the entity that owns them. And by unclear, I mean completely silent. In fact, IMO the wording in the spec implies that the callback should not happen since pre/post update is supposed to happen before/after SQL UPDATE statements are sent for that entity.

    Now, if the owning entity is versioned Hibernate treats changes to any collections (any attributes really) it owns as forcing a version increment on the owning entity which will trigger the update of the entity which will in turn trigger the post-update callback.

    0 讨论(0)
提交回复
热议问题