Hibernate如何忽略@Where注释 [英] Hibernate how to ignore @Where annotation
问题描述
我有一个实体:
@Entity
@Table(name =[Usermaster])
@Where(clause =isDeleted = 0)
public class User {
// ...
}
在某些流程中,我需要忽略@Where注释并获取用户,即使isDeleted不为0。 (我使用CRUD库进行查询)
@Where code>设置,它是 @Filter
。请参阅:
Hibernate有能力预先定义过滤条件并附加这些过滤器无论是课堂级别还是集合级别。过滤条件允许您定义一个类似于类和各种集合元素上现有的其中
属性的限制条款。
@Filter的管理更简单一些:
<需要定义过滤器
-
< filter-def>
/ @FilterDef
/ li>
-
< filter>
/ @Filter
必须分配给class或a set
- 过滤器必须在会话级别启用,例如:
session.enableFilter(myFilter)。setParameter(myFilterParam,some-value) ;
所以,这虽然稍微复杂一点,但它提供了我们需要的东西:dynamic @Where
在运行时打开/关闭
I have an entity:
@Entity
@Table(name = "[Usermaster]")
@Where(clause = "isDeleted = 0")
public class User {
//...
}
in some flow I need to ignore @Where annotation and get user even if isDeleted is not 0. How can I make it? (I use CRUD repositories to query)
解决方案 There is a dynamic version of the @Where
setting, it is the @Filter
. See:
Hibernate has the ability to pre-define filter criteria and attach those filters at both a class level and a collection level. A filter criteria allows you to define a restriction clause similar to the existing "where"
attribute available on the class and various collection elements.
Management of @Filter is a bit more complex, in a nutshell:
<filter-def>
/ @FilterDef
is needed to define filter
<filter>
/ @Filter
must be assigned to class or a set
- filter must be enabled on a session level, e.g.:
session.enableFilter("myFilter").setParameter("myFilterParam", "some-value");
So, this, while being a bit more complex, provides exactly what we need: dynamic @Where
to be turned on/off in run-time
这篇关于Hibernate如何忽略@Where注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!