如何使用Hibernate为Spring数据JPA的所有查找方法添加全局where子句? [英] How to add global where clause for all find methods of Spring data JPA with Hibernate?

查看:97
本文介绍了如何使用Hibernate为Spring数据JPA的所有查找方法添加全局where子句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用带有Hibernate的Spring数据JPA来开发Web应用程序.

We are working on web application using Spring data JPA with hibernate.

在应用程序中,每个实体中都有一个compid字段. 这意味着在每个数据库调用(Spring Data方法)中,都必须使用compid进行检查.

In the application there is a field of compid in each entity. Which means in every DB call (Spring Data methods) will have to be checked with the compid.

我需要一种方式,这个"where compid =?"检查为每种查找方法自动注入. 这样我们就不必专门为compid检查而烦恼了.

I need a way that, this "where compid = ?" check to be injected automatically for every find method. So that we won't have to specifically bother about compid checks.

这可以从Spring Data JPA框架中实现吗?

Is this possible to achieve from Spring Data JPA framework?

推荐答案

也许Hibernate的注释@Where会为您提供帮助.它将传递的条件添加到与该实体相关的任何JPA查询中.例如

Maybe Hibernate‘s annotation @Where will help you. It adds the passed condition to any JPA queries related to the entity. For example

@Entity
@Where(clause = "isDeleted='false'")
public class Customer {
    //...
    @Column
    private Boolean isDeleted;
}

更多信息: 1 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆