Hibernate中对所有表的所有查询的通用条件限制 [英] Common criteria restriction in Hibernate for all queries for all tables

查看:232
本文介绍了Hibernate中对所有表的所有查询的通用条件限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在hibernate中为我的项目编写了很多查询。现在我的要求已经改变,我在MySql中的所有表中都添加了一个新的列名ACTIVE。我无权拒绝添加ACTIVE列。 ACTIVE字段可以保存值true或false,我也必须将其添加到条件中。所以,我一直在想,有没有一种方法可以在Hibernate中添加一个标准限制,这对我所做的所有查询都是常见的,而不是为我所做的每个查询都设置标准?

I have already finished writing a lot of queries in hibernate for my project. Now my requirement has changed and a new column name ACTIVE is added in all the tables I have in MySql. I have no permission to deny the addition of ACTIVE column. The ACTIVE field can hold values true or false and I have to add that to the criteria too. So, I have been thinking is there a way I could add a criteria restriction in Hibernate that is kind of common to all the queries I make, instead of putting that criteria for every query I make?

编辑:我猜想有点误会,对不起,我在打字的时候匆匆忙忙。
其他用户已将ACTIVE列设置为true或false。我需要的是一个全局过滤,仅针对我发出的每个查询的ACTIVE列为true的记录。

Little misunderstanding I suppose, sorry for that, I was in hurry while typing this. The ACTIVE column will be already set to true or false by some other user. What I need to is a global filtering only for the records having ACTIVE column as true for every query I fire.

这样的东西但是我希望hibernate为我发出的每个查询添加ACTIVE ='true'过滤器,

Something like this but I want hibernate to add the the ACTIVE='true' filter for every query I fire,

select name from table where <other-conditions-here> and ACTIVE='true'

希望有意义。

谢谢和问候,

Sunayan Saikia

Sunayan Saikia

推荐答案

您可以使用休眠过滤器来实现此目的。有关详细信息,请参阅 doc

You can use hibernate filters for this purpose. for details refer doc

这篇关于Hibernate中对所有表的所有查询的通用条件限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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