首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

hibernate: 用Disjunction跟Conjunction构造复杂的查询条件

2013-10-31 
hibernate: 用Disjunction和Conjunction构造复杂的查询条件http://blog.csdn.net/whqcfp/article/details/

hibernate: 用Disjunction和Conjunction构造复杂的查询条件
http://blog.csdn.net/whqcfp/article/details/6029061
Disjunction和Conjunction是逻辑或和逻辑与,可以用这个来构造复杂的SQL查询条件,实例如下:

 private void CheckBsc_lj(Criteria queryCriteria)  {  Disjunction disjunction = Restrictions.disjunction();  Criterion cirterion = Restrictions.sqlRestriction("SIMULPORTCAPACITY<SIMULPORTCAPACITYOCUPIED".toLowerCase());  disjunction.add(cirterion);  cirterion = Restrictions.sqlRestriction("ADSLPORTCAPACITY<ADSLPORTCAPACITYOCCUPIED".toLowerCase());  disjunction.add(cirterion);  cirterion = Restrictions.sqlRestriction("LANPORTCAPACITY<LANPORTCAPACITYOCCUPIED".toLowerCase());  disjunction.add(cirterion);    // ONU端口,至少要录入一种端口  Conjunction conjunction = Restrictions.conjunction();  cirterion = Restrictions.eq("lanportcapacity", 0);  conjunction.add(cirterion);  cirterion = Restrictions.eq("simulportcapacity", 0);  conjunction.add(cirterion);  cirterion = Restrictions.eq("adslportcapacity", 0);  conjunction.add(cirterion);  disjunction.add(conjunction);  queryCriteria.add(disjunction); }


构造出的条件如下:
select *  from aaaa this_ where (simulportcapacity < simulportcapacityocupied or       adslportcapacity < adslportcapacityoccupied or       lanportcapacity < lanportcapacityoccupied or       (this_.LANPORTCAPACITY = ? and this_.SIMULPORTCAPACITY = ? and       this_.ADSLPORTCAPACITY = ?))

热点排行