Hibernate 如何使用filter

本文详细介绍了如何在特定的编程环境下,通过定义filter参数来优化对象关联查询的性能和效率,具体涉及到如何在查询中应用filter名称、设置参数以及实现过滤条件的应用。
@entity
@table(name = "t_sen_disability_type")
在使用filter的时候还需要定义filter参数。 name 为filter名称,parameters为filter参数,@paramdef为参数定义,其中那么为apporcase(参数名称) type为该参数类型
@filterdef(name = "apporcasefilter", parameters = @paramdef(name = "apporcase", type = "string"))
public class disabilitytype extends identity {
private list<specneedquestion> specneedquestions;

@onetomany(fetch = fetchtype.lazy)
@filters( { @filter(name = "apporcasefilter", condition = ":apporcase=app_or_case") })
@joincolumn(name = "dis_type_id")
@orderby("qstindex")
public list<specneedquestion> getspecneedquestions() {
return specneedquestions;
}

public void setspecneedquestions(list<specneedquestion> specneedquestions) {
this.specneedquestions = specneedquestions;
}
@filters定义该对象关联specneedquestion对象是对应的所有的filters。
@filter 指定单个的filter 属性:name为filter的名字。condition为filter的过滤条件,其中:app_or_case为specneedquestion对象对应的表的字段,:apporcase为参数名称。

public list<disabilitytype> getdisables(string apporcase) {
string hql = "from disabilitytype t order by t.type";
session session = this.getsession();
filter filter = session.enablefilter("apporcasefilter");
filter.setparameter("apporcase", apporcase);
return find(hql);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值