Common criteria restriction in Hibernate for all queries for all tables

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?

EDIT: 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.

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'

Hope that make sense.

Thanks and regards,

Sunayan Saikia


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


I would advice you to implement a custom interceptor, Which should intercept your queries and append ACTIVE criteria before they are executed.

Interceptor details could be found here: Hibernate Interceptors

链接地址: http://www.djcxy.com/p/37120.html

上一篇: Hibernate Criteria Query用于IN子句和子查询的多列

下一篇: 在所有表的所有查询中,Hibernate的通用标准限制