JPA event listener is not called when saving collection of embeddables
Description
duplicates
relates to
Activity
Vlad Mihalcea June 1, 2018 at 11:46 AMEdited
I think that the JPA spec GitHub issue provides a lot of context for this issue.
1. The JPA spec is vague in this regard. Therefore, the spec should change to specify clearly if element collection changes should trigger a Pre/PostUpdate
event.
2. I think it's much better if JPA defines a @Pre/PostCollectionPersist
event listeners because, this way, we can differentiate between entity state changes and associated element collection changes. Grouping those together will make it hard figuring out what's changed.
3. With Hibernate, you already have a workaround since we define the Pre/PostCollectionUpdateEventListener
.
4. You can achieve a similar goal, even without relying on Hibernate, by just using database triggers or CDC (e.g. Debezium).
For these reasons, I don't think we should change the current Hibernate behavior.
However, I won't close this issue since this is just my opinion and maybe someone else from the team has a different view on this subject.

Petar Tahchiev September 8, 2017 at 7:15 AM
Hi Andrea,
thank you for your comment. I have implemented this and it works. However, this looks like a Hibernate way only. Is it possible to achieve the same thing with JPA?

Andrea Boriero September 7, 2017 at 4:50 PM
Hi ,
to use a custom
you have to register it, in your case you can do it in this way
you can find more details in the documentation http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#bootstrap-event-listener-registration

Yoana Ivanova September 7, 2017 at 12:55 PM
I have the same problem too, any ideas for a solution or a workaround?

Petar Tahchiev September 3, 2017 at 11:07 AM
Hey guys, any update on this on?
I have the following entity:
where the
LocalizedValue
is the followingEmbeddable
:When I change a simple property on the
Product
andmerge
it, then the JPA event listeners are called. However when I change thedescription
and merge it, my JPA entity event listener is never called.I will attach a failing test-case soon.