Files
hibernate-demo/soft-delete/src/main/java/com/ankurm/softdelete/ArticleManual.java
T

26 lines
871 B
Java

package com.ankurm.softdelete;
import jakarta.persistence.*;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;
/** The hand-rolled recipe that predates {@code @SoftDelete}: a mapped column, an UPDATE instead of DELETE, a WHERE on every read. */
@Entity
@Table(name = "article_manual")
@SQLDelete(sql = "update article_manual set deleted = true where id = ?")
@SQLRestriction("deleted = false")
public class ArticleManual {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
@Column(nullable = false)
private boolean deleted;
protected ArticleManual() {}
public ArticleManual(String title) { this.title = title; }
public Long getId() { return id; }
public String getTitle() { return title; }
public boolean isDeleted() { return deleted; }
}