HQL多表联合查询的问题

 HQL查询多表的时候,取出结果是两个对象的列表,但是我只要我自己想要的属性,之前的HQL语句是这样写的:
from  Hytxbz h,Tgbzk t  where  h.hytxbzid = t.hytxbzid  and  t.bztgid = :bztgid
结果我debug去看query.list();是Hytxbz和Tgbzk两个对象的列表,结果并不是我想要的,我改成
from  Hybztx h  where  h.hytxbzid  in  ( select  t.hytxbzid  from  Tgbzk  where  t.bztgid  = :bztgid)
还是不行,google一把,发现可以这样写
select  h  from  Hytxbz  as  h,Tgbzk  as  t  where  h.hytxbzid = t.hytxbzid  and  t.bztgid = :bztgid
如果想取得对应属性的话,也可以这样写
select  h.hytxbzid  from  Hytxbz  as  h,Tgbzk  as  t  where  h.hytxbzid = t.hytxbzid  and  t.bztgid = :bztgid
发现in的语句可以这样写
String   ids[] = new    String[] {"1","2","3"} ;   
    
  String   hql
=     "    from   com,you.YourPOJO   where   id   in   (?) " ;   
    
    Query   query   
=    session.createQuery(hql);   
  query   .setParameters(ids);   
    
  相关方法:   
    
    Query   setParameters(Object[]   objectArray,   Type[]   typeArray)   
throws    HibernateException;   
      Query   setParameterList(String   string,   Collection   collection,   Type   type)   
throws    HibernateException;   
      Query   setParameterList(String   string,   Collection   collection)   
throws    HibernateException;   
      Query   setParameterList(String   string,   Object[]   objectArray,   Type   type)   
throws    HibernateException;   
      Query   setParameterList(String   string,   Object[]   objectArray)   
throws    HibernateException
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值