在使用Hibernate或者JPA時,咱們常常會使用@Where註解實現查詢過濾,在實體類上、實體屬性上、查詢語句上都有應用。spa
例如:code
@Where(clause = "status != -1")
List<SalarySheetEntity> findAllByCreatedByOrderByIdDesc(String login);
@Where(clause = "status != -1") public class SmsAccountEntity extends AbstractAuditingEntity {}
注意:應用在查詢時須要注意,不能夠應用在count上,註解源碼可知:blog
/** * Where clause to add to the element Entity or target entity of a collection. The clause is written in SQL. * A common use case here is for soft-deletes. * * @author Emmanuel Bernard */ @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface Where { /** * The where-clause predicate. */ String clause(); }