Control before deletion (action)


I would like to perform a check when deleting a record (click the deleted button on the form).
Except I haven’t seen anything like onDelete or anything else, can you tell me how this is done?


PS :
I saw a canDelete but I would like to be able to make a request in db to check if there are links with other objects before authorizing the deletion

You can override remove method.


I did not find this method? do you have his name?

Thanks for your answers.

Try like this

1 J'aime

i’m thinking about it, I’m new to development, but the idea in my mind is that when a user wants to delete a record, its just make inactive. then we can check these records through the database or do a complete cleaning.
please let me know your answer so that I can improve myself if I have a mistake as an idea or if it is open to improvement.
best regards

could listeners be the solution ?

Hi ple-essieux,

Thanks for your help

I just need to create my own packages and extend my entity’s class repository ? The code you show is already in AOP, it’s for an object that I created that I want to overload the delete button to add controls before deletion.

Like @ple-axelor said, you can overide the remove function in the dao/repository so you can edit this to inactive rather than deleting. For this, you have to create a new class, extends from the repository and bind it in the module file.

WOW it’s starting to get tense lol the dao package is a self-generating package, I have to create my own packages in the java source directory? do you have an example please?

When I develop, I use my own package because I use custom module.
I create a module like this :
and I configure it with settings.gradle and build.gradle at the root of the axelor project

So I too create my own modules under eclipse, however when you create your DOMAIN XML files it generates the repositories even if you have a custom module, that’s where I’m lost… I hope I got it right Explain.

Yeah when you create new domain, it create new repositories.
If you want to add properties to extistant domain, you have to create a domain file in your own module and set the exact name and package that the axelor domain which already exist.

Initial Invoice domain :

Add a propertie named contract to Invoice domain :

Hi PHPierre,

Yes I know that, but we are just talking about the .xml in the « domain » package, this will generate java classes in the build/src-gen/java package like:
« .repo »
with class repositories in it.

I can’t modify these class to add my overload

public void remove(BankReconciliation entity) {

like your example above because these files are generated.
How do I do it ?

Thanks for your help.

I am sharing the gist, where you can see the method of catching domain object before removal

I have used the entity listener method, where I can catch any events, you can see further events here

1 J'aime

Ok the call works well, however how do I cancel the delete action, I saw that you are rolling back from an exception. I would just like to do a test and if the test is good I don’t do the deletion. How can I do this?

I have not tested that part, jpa entity listener can help. @SQLDELETE and @Where clause of those can be helpful