Controlling deletion in specifically related entity

We use @onDelete annotation when we want to control deletion of an entity preventing data redundancy. this works very well and I’m using this as and where needed.

Now my requirement is a bit different. Let me explain with an example. Say I have 3 Entity. Account, CostCentre and Transaction. Account and CostCentre are related Many to Many. Each record in Transaction Entity has both Account and CostCentre entities. I want to deny deletion of specific relationship between Account and CostCentre if this pair of Account-CostCentre is used in any record in Transaction Entity. Is there any way to achieve this through annotations or other good solutions?

You cannot do this declaratively by annotations, so use a BeforeDeleteEntityListener

Hi Konstantin
Thanks. If I use BeforeDeteleEntityListener, I have two supplementary questions:
a) Which API is appropriate to recall this delete or update as I didn’t see anything suitable in the user guide (may be I have missed)
b) How can I send message (standard CUBA message) to the users

Thanks.

You can throw an exception and show an appropriate message to users using exception handlers. In case of an exception, the current transaction will be rolled back and deletion will be aborted.

Thank you so much Konstantin.