# Embeddable callbacks

**URL:** <https://discourse.hibernate.org/t/embeddable-callbacks/9702>\
**Category:** Hibernate ORM\
**Created:** [June 5, 2024, 12:18pm UTC](https://discourse.hibernate.org/t/embeddable-callbacks/9702 "2024-06-05T12:18:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mira-silhavy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mira-silhavy/32/2811_2.png) [@mira-silhavy](https://discourse.hibernate.org/u/mira-silhavy)\
**Post date:** [June 5, 2024, 12:18pm UTC](https://discourse.hibernate.org/t/embeddable-callbacks/9702/1 "2024-06-05T12:18:10Z")

</div>

Hi,  
is there some way to add a callback to Embeddable similar to what entities have? E.g. PostUpdate/PostPersist or PostUpdateEventListener?

I have few collections in embeddables that need some extra processing after update/persist. For entities it works like a charm, but I’m having issues with Embeddable.

Thanks

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [June 5, 2024, 1:56pm UTC](https://discourse.hibernate.org/t/embeddable-callbacks/9702/2 "2024-06-05T13:56:47Z")

</div>

AFAICS, this was implemented as part of [[HHH-12326] - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-12326). If you have trouble with the feature, please try to create a reproducer with our [test case template](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) and if you are able to reproduce the issue, create a bug ticket in our [issue tracker](https://hibernate.atlassian.net) and attach that reproducer.

---

<div class="post-metadata">

**Author:** ![mira-silhavy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mira-silhavy/32/2811_2.png) [@mira-silhavy](https://discourse.hibernate.org/u/mira-silhavy)\
**Post date:** [June 5, 2024, 2:40pm UTC](https://discourse.hibernate.org/t/embeddable-callbacks/9702/3 "2024-06-05T14:40:43Z")

</div>

I just found this [@ManyToMany and PostUpdateEventListener](https://discourse.hibernate.org/t/manytomany-and-postupdateeventlistener/979), my collection inside the embeddable is also ManyToMany. I guess this mean it won’t work, is that correct?

---

<div class="post-metadata">

**Author:** ![mira-silhavy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mira-silhavy/32/2811_2.png) [@mira-silhavy](https://discourse.hibernate.org/u/mira-silhavy)\
**Post date:** [June 5, 2024, 3:05pm UTC](https://discourse.hibernate.org/t/embeddable-callbacks/9702/4 "2024-06-05T15:05:42Z")

</div>

I tried @PreUpdate, event listeners on embeddable and nothing is called by hibernate when the collection is modified.

---

<div class="post-metadata">

**Author:** ![mira-silhavy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mira-silhavy/32/2811_2.png) [@mira-silhavy](https://discourse.hibernate.org/u/mira-silhavy)\
**Post date:** [June 6, 2024, 12:15pm UTC](https://discourse.hibernate.org/t/embeddable-callbacks/9702/5 "2024-06-06T12:15:08Z")

</div>

Hi @beikov,  
If I have a collection in an entity either ManyToMany or OneToMany, should the owning entity be notified in PreUpdate/PostUpdate when I modify the collection?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [June 6, 2024, 5:07pm UTC](https://discourse.hibernate.org/t/embeddable-callbacks/9702/6 "2024-06-06T17:07:10Z")

</div>

That’s a good question. I think you should start a discussion about this on our [Zulip chat platform](https://hibernate.zulipchat.com/#narrow/stream/132096-hibernate-user).

---

<div class="post-metadata">

**Author:** ![mira-silhavy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mira-silhavy/32/2811_2.png) [@mira-silhavy](https://discourse.hibernate.org/u/mira-silhavy)\
**Post date:** [June 7, 2024, 12:40pm UTC](https://discourse.hibernate.org/t/embeddable-callbacks/9702/7 "2024-06-07T12:40:50Z")

</div>

Solved by using `PreCollectionRecreateEventListener` and `PreCollectionUpdateEventListener`.
