论坛首页 Java企业应用论坛

求证:hql多条件from时丢失参数?

浏览 3734 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-01-22   最后修改:2009-12-27
最近做一个项目,用from对对象进行查询,结果查出重复数据(composite-id,但是key是正确地override了equals和hashCode)。

让hibernate输出生成的native sql发现
from PerformScript where  key.pcd='123456' and key.interviewSheetNo='123456'  and ( startDay=null or startDay='' or startDay<='20070122') and ( endDay=null  or endDay='' or endDay>='20070122' )) and kind='pc'  order by key.relatNo 

生成的是
select performscr0_.p_code as p1_26_, performscr0_.sheet_no as sheet2_26_, performscr0_.relat_no as relat3_26_, performscr0_.kind as kind26_, performscr0_.script as script26_, performscr0_.start_day as start6_26_, performscr0_.end_day as end7_26_ from perform_script performscr0_ 
where performscr0_.p_code='123456' and performscr0_.sheet_no='123456' and (performscr0_.start_day is null or performscr0_.start_day='' or performscr0_.start_day<='20070122') and (performscr0_.end_day is null or performscr0_.end_day='' or performscr0_.end_day>='20070122')

其中kind='pc'丢失了。
但是如果切换一下顺序
from PerformScript where  key.pcd='123456' and key.interviewSheetNo='123456' and kind='pc'   and ( startDay=null or startDay='' or startDay<='20070122') and ( endDay=null  or endDay='' or endDay>='20070122' )) order by key.relatNo 

select performscr0_.p_code as p1_26_, performscr0_.sheet_no as sheet2_26_, performscr0_.relat_no as relat3_26_, performscr0_.kind as kind26_, performscr0_.script as script26_, performscr0_.start_day as start6_26_, performscr0_.end_day as end7_26_ from perform_script performscr0_ 
where performscr0_.p_code='123456' and performscr0_.sheet_no='123456' and 
[b]performscr0_.kind='pc' [/b]
and (performscr0_.start_day is null or performscr0_.start_day='' or performscr0_.start_day<='20070122') and (performscr0_.end_day is null or performscr0_.end_day='' or performscr0_.end_day>='20070122')

条件又出来了。

估计是hibernate的bug。
除非hibernate输出的sql有长度限制。

有碰到同样问题的xdjm没?
   发表时间:2007-01-22  
没事用那么多个括号干什么?也没有or都是and需要么?
   1. from PerformScript where  key.pcd='123456'
and key.interviewSheetNo='123456' 
and ( startDay=null or startDay='' or startDay<='20070122')
and ( endDay=null  or endDay='' or endDay>='20070122' ))
and kind='pc'  order by key.relatNo  
0 请登录后投票
   发表时间:2007-01-23  
sql问题
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics