我想知道是否可以使用jpa或hibernate建立一个查询,以使用特定语言环境(例如“
it”)的Dictionary检索ApplicationForm实体。
不适用于标准JPA。但是Hibernate允许在给定的会话期间将任意过滤器应用于收集负载。从《 Hibernate注释参考指南》中:
2.4.8。筛选器
Hibernate可以在数据之上应用任意过滤器。这些过滤器将在运行时应用于给定的会话。首先,您需要定义它们。
@org.hibernate.annotations.FilterDef
或@FilterDefs使用相同的名称定义过滤器使用的过滤器定义。过滤器定义具有name()和的数组parameters()。参数将允许您在运行时调整过滤器的行为。每个参数由@ParamDef具有名称和类型的定义。您也可以defaultCondition()为给定定义一个
参数,@FilterDef以设置在每个个人中都未定义的默认条件@Filter。甲@FilterDef(或多个)可以在类或包级别来定义。现在,我们需要定义应用于实体加载或集合加载的SQL filter子句。
@Filter用于实体或集合元素上
> @Entity> @FilterDef(name="minLength", parameters=@ParamDef( name="minLength",> type="integer" ) )> @Filters( {> @Filter(name="betweenLength", condition=":minLength <= length and> :maxLength >= length"),> @Filter(name="minLength", condition=":minLength <= length")> } )> public class Forest { ... }当集合使用关联表作为关系表示形式时,您可能希望将过滤条件应用于关联表本身或目标实体表。要将约束应用于目标实体,请使用常规
@Filter
注释。但是,如果要定位关联表,请使用@FilterJoinTable注释。
> @OneToMany> @JoinTable> //filter on the target entity table> @Filter(name="betweenLength", condition=":minLength <= length and> :maxLength >= length")> //filter on the association table> @FilterJoinTable(name="security", condition=":userlevel >=> requredLevel")> public Set<Forest> getForests() { ... }也可以看看
- Hibernate Core参考文档中的第17章过滤数据。
- Hibernate3过滤器



