Is there a way to cancel object creation in afterCreate event handler?

According to my business rules I need to perform a certain operation only after the entity was validated and created. However, if this operation fails, I need to rollback the whole transaction. What is the correct way to do it? If I throw an exception from afterCreate callback, the entity is still saved.

Hello, Kateryna!

If the process is already in the “afterCreate” handler - then the object is created, at it cannot be “rolled back”. However, you can call “remove” method inside the handler to remove the created object.
best regards,
Alex

Thank you for the quick answer. This is not very convenient, but it will do.