Override default remove () / DELETE to JPA / Hibernate

Instead of deleting the record, our client would like to mark the record as deleted. We use JPA2 / Hibernate. I would like to do something like the following:

@Entity @Table(name="TABLE") @ActionOverride(action="delete", with="activeFlag = false") public class Table { @Column(name="ACTIVE_FLAG") boolean activeFlag; // ... } 

I have done this in the past, but I cannot find the correct syntax and annotation.

+4
source share
2 answers

Take a look at the hibernate documentation, the annotation you are looking for is @SQLDelete .

 @Entity @Table(name="TABLE") @SQLDelete(sql = "UPDATE TABLE SET ACTIVE_FLAG = false WHERE id = ?") public class Table { @Column(name="ACTIVE_FLAG") boolean activeFlag; // ... } 
+8
source

The annotation looks like org.hibernate.annotations.SQLDelete :

SqlDelete Annotations for overwriting the default DELETE method for Hibernate

You install your own SQL update in the sql attribute.

+1
source

Source: https://habr.com/ru/post/1397655/


All Articles