Preventing entries from being deleted using Hibernate

Asked

Viewed 76 times

0

Is there any way I can set that certain table entry in the database is not excluded?

For example, I created a table usuários on the bench through the class User using the annotations of Hibernate and JPA and wish that Admin User could not be deleted.

  • 1

    By directly placing the register of a main administrator in the bank, you could not provide the exclusion option, checking in the bank and returning an error if you are the Administrator. I don’t know if there’s anything proper to Hibernate/JPA for this.

1 answer

1

I think that this access control of a certain user is by means of a database in which you are using, for example in MYSQL:

Gerenciamento de Acesso ao Banco de Dados

Database Access Management Or put some condition in your application that when the Admin User user is using your application it is not possible to execute the SQL code to remove the record, example:

Check on removing record from a table:

Verificação na remoção de registro de uma tabela

  • What do you mean? You are suggesting that the user execute a drop table!?

  • @Wakim to suggest not to run just look at the condition... if the user is "Admin User" do not run the drop table.

  • Yes, but a record with drop table (this will delete the table) and yes with a delete, but he probably already uses the delete of JPA for that.

  • 1

    "Certain table entry in the database is not excluded"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.