當需要過濾實體類的數據時,根據偽刪除字段進行過濾,需要使用Hibernate提供的@Where注解
使用方式:

@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 }
官方文獻:https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#pc-where
注意:@Where部分注解不支持超類(@MappedSuperClass),需要定義在需要使用的具體實體類上