hibernate inner join查询结果问题

东哥捱挮 2010-04-03 11:09:50
小弟相死,想上代码
从表

<many-to-one name="tblDrpBusiness" class="com.teamsun.drp.po.TblDrpBusiness" fetch="join" lazy="false">
<column name="Business_id" length="4" />
<column name="version" length="10" />
</many-to-one>

主表

<set name="tblDrpBuExeIndexes" inverse="true" lazy="true">
<key>
<column name="Business_id" length="4" />
<column name="version" length="10" />
</key>
<one-to-many class="com.teamsun.drp.po.TblDrpBuExeIndex" />
</set>


hql查询语句

"select t.tblDrpBuExeIndexes from TblDrpBusiness t inner join t.tblDrpBuExeIndexes e where t.id.businessId='"+businessID+"' and t.id.version='"+version+"' and e.exeFlag <> 'DONE' and e.exeFlag <> 'CANCEL'"

解释下啊。由于hibernate版本问题,就加上inner join 了,不然会报错。但是加后不报错了,数据结果又不对了
select tbldrpbuex2_.Bu_exe_seq as Bu1_21_, tbldrpbuex2_.Bu_exe_name as Bu2_21_,
tbldrpbuex2_.Exe_start_t as Exe3_21_, tbldrpbuex2_.Exe_end_t as
Exe4_21_, tbldrpbuex2_.Cur_step as Cur5_21_, tbldrpbuex2_.Exe_flag
as Exe6_21_, tbldrpbuex2_.Fail_flag as Fail7_21_, tbldrpbuex2_.operator
as operator21_, tbldrpbuex2_.Lauch_site as Lauch9_21_,
tbldrpbuex2_.Control_site as Control10_21_, tbldrpbuex2_.Step_seq
as Step11_21_, tbldrpbuex2_.Context_para_value as Context12_21_,
tbldrpbuex2_.Ip_addr as Ip13_21_, tbldrpbuex2_.Cmd_count as
Cmd14_21_, tbldrpbuex2_.Reply_count as Reply15_21_, tbldrpbuex2_.Info_count
as Info16_21_, tbldrpbuex2_.Operation_result as Operation17_21_ from
drp.tbl_drp_business tbldrpbusi0_ inner join drp.tbl_drp_bu_exe_index tbldrpbuex1_ on
tbldrpbusi0_.Business_id=tbldrpbuex1_.Business_id and tbldrpbusi0_.version=tbldrpbuex1_.version
inner join drp.tbl_drp_bu_exe_index tbldrpbuex2_ on
tbldrpbusi0_.Business_id=tbldrpbuex2_.Business_id and tbldrpbusi0_.version=tbldrpbuex2_.version where
tbldrpbusi0_.Business_id='1021' and tbldrpbusi0_.version='V1.0' and tbldrpbuex1_.Exe_flag<>'DONE'
and tbldrpbuex1_.Exe_flag<>'CANCEL'

生成出的SQL有两个inner join,结果当然不对咯,你看相死不
然后手动改SQL,删除其中inner join
select tbldrpbuex2_.Bu_exe_seq as
Bu1_21_, tbldrpbuex2_.Business_id as
Business2_21_, tbldrpbuex2_.version as
version21_, tbldrpbuex2_.Bu_exe_name as
Bu4_21_, tbldrpbuex2_.Exe_start_t as
Exe5_21_, tbldrpbuex2_.Exe_end_t as
Exe6_21_, tbldrpbuex2_.Cur_step as
Cur7_21_, tbldrpbuex2_.Exe_flag as
Exe8_21_, tbldrpbuex2_.Fail_flag as
Fail9_21_, tbldrpbuex2_.operator as
operator21_, tbldrpbuex2_.Lauch_site as
Lauch11_21_, tbldrpbuex2_.Control_site as
Control12_21_, tbldrpbuex2_.Step_seq as
Step13_21_, tbldrpbuex2_.Context_para_value as
Context14_21_, tbldrpbuex2_.Ip_addr as Ip15_21_,
tbldrpbuex2_.Cmd_count as Cmd16_21_, tbldrpbuex2_.Reply_count
as Reply17_21_, tbldrpbuex2_.Info_count as Info18_21_,
tbldrpbuex2_.Operation_result as Operation19_21_ from
drp.tbl_drp_business tbldrpbusi0_ inner join
drp.tbl_drp_bu_exe_index tbldrpbuex2_ on tbldrpbusi0_.Business_id=tbldrpbuex2_.Business_id
and tbldrpbusi0_.version=tbldrpbuex2_.version
where tbldrpbusi0_.Business_id='1021' and tbldrpbusi0_.version='V1.0'
and tbldrpbuex2_.Exe_flag<>'DONE' and tbldrpbuex2_.Exe_flag<>'CANCEL'

结果相当完美。就是我想要的
狗日的,网上查了,不知道如何查啊。似乎没人遇到过这狗屁问题。高人赐教。。hibernate真头痛。希望高人提供有价值。。解决办法
...全文
325 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
inritxihc 2010-04-03
  • 打赏
  • 举报
回复
from TblDrpBuExeIndexes as e where e.tblDrpBusiness.id.businessId='"+businessID+"' and e.tblDrpBusiness.id.version='"+version+"' and e.exeFlag <> 'DONE' and e.exeFlag <> 'CANCEL'" 这样中不?
复杂的查询还是用jdbc方便
inritxihc 2010-04-03
  • 打赏
  • 举报
回复
好多语句啊,看了两眼头都大了。。

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧