Home > front end >  Can we make spring entity not delete able by any user?
Can we make spring entity not delete able by any user?

Time:01-17

I'm using postgres with my spring boot app and I want to make a specific table not delete able by anyone. Is there a way to implement this on spring boot side.

Revoking delete grant does the job on postgres side but I want to configure entity such that it won't be delete able by anyone.

CodePudding user response:

Create a trigger on the table to prevent deletion:

create function prevent_deletion()
returns trigger as '
begin
    raise exception ''deletion not allowed'';
end;
' language plpgsql;


create trigger prevent_deletion_trigger 
before delete on mytable
for each row 
execute function prevent_deletion();

See live demo.

CodePudding user response:

If you use JPA you could overload the delete methode from the Repository. None is then able to delete entries over it.

  • Related