SpringDataJpa entity class pseudo-delete filter

When the need to filter the data entity class, filtered pseudo delete a field, you require the use of Hibernate annotations @Where

Use:

@Entity(name = "Account")
@Where( clause = "active = true" )
public static class Account {

    @Id
    private Long id;

    @ManyToOne
    private Client client;

    @Column(name = "account_type")
    @Enumerated(EnumType.STRING)
    private AccountType type;

    private Double amount;

    private Double rate;

    private boolean active;

    //Getters and setters omitted for brevity

}
View Code

 

The official document: https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#pc-where

 

Note: @Where part of the annotation does not support the superclass (@MappedSuperClass), you need to define the specific entity class in need of

 

Guess you like

Origin www.cnblogs.com/XingXiaoMeng/p/11403177.html