Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support domain events for deletions [DATACMNS-1663] #2084

Closed
spring-projects-issues opened this issue Jan 30, 2020 · 8 comments
Closed

Support domain events for deletions [DATACMNS-1663] #2084

spring-projects-issues opened this issue Jan 30, 2020 · 8 comments
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

Oliver Behncke opened DATACMNS-1663 and commented

When saving an entity in a CrudRepository, the events available in the method annotated with @DomainEvents are published.

 

However, when deleting an entity with the same repository, none of the events are published. Explicitly, in EventPublishingMethodInterceptor#invoke only methods starting with "save" are considered to trigger publishing of the events.

 

It would be nice, if the domain events would be published on delete, to avoid injecting the spring framework class ApplicationEventPublisher into the domain related code


Affects: 2.2.4 (Moore SR4)

Referenced from: pull request #436

8 votes, 5 watchers

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

That's merged for 2020.0.0

@kevinchan-rl
Copy link

hey guys I noticed deleteById also does not publish, should this be fixed?

@odrotbohm
Copy link
Member

How would a deleteById(…) produce an event in the first place?

@amariik
Copy link

amariik commented Jun 6, 2023

Wouldn't @PrePersist/PreRemove etc potentially trigger the creation of some events which should be published?

@odrotbohm
Copy link
Member

That's a good point. I'll have to investigate, but from a quick glance, I think that only JPA currently supports entity-attached lifecycle callbacks. This means, that while adding deleteById(…) to the list of event publishing methods, there's still no way to let that trigger event publication in, for example, stores like MongoDB.

@odrotbohm
Copy link
Member

I've investigated the support for deleteById(…) and have come to the conclusion that we cannot support this properly. The event publication mechanism relies on the aggregate instance(s) to be handed to the repository. Even if we assume that deleteById(…) loads these before deletion, the JPA specific lifecycle events fire deep down within the JPA implementation, and we cannot reasonably pick up the events created so deep down the call stack.

@amariik
Copy link

amariik commented Jun 12, 2023

That is understandable. I think it would be a nice to have but not a must have. We only ran into this recently and switching to using the normal delete() was simple enough in our case. It was however surprising at first glance. I appreciate you digging into this.

@odrotbohm
Copy link
Member

I guess we can still add a bit of clarification in the reference documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants