Check before deletion


I am looking to perform a check before deleting a record: a check for example:
if(true) {
we delete the recording
cancel the deletion

I started by implementing a listener (this one does get called when I click the delete button on a project, but I don’t know how to prevent the record from being deleted.

Can you help me please ? Thanks.

My code java for listener :

package com.axelor.apps.ordered.db.repo;

import com.axelor.apps.project.db.Project;
import java.lang.invoke.MethodHandles;
import javax.persistence.PreRemove;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ProjectListener {

private final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

@Transactional(rollbackOn = {Exception.class})
private void onPreRemove(Project project) {

log.debug("before removing " + project.getId());
Boolean resultat = false;
if (!resultat) {
  log.debug("cancel the deletion");


if you throw exception it will be rolled back, you have written it :slight_smile:

ok so I just throw an exception style: throw new exception()? I will test. Thanks for your return.

Great that’s ok, I hadn’t thought of that… You’re a chef. Thanks.

Ce sujet a été automatiquement fermé après 30 jours. Aucune réponse n’est permise dorénavant.