有两个表A表和B表,A和B是一对多关系,在A的实体类中有一个Set属性cc对应B表,在B表中有个对象dd代表所对应的表A
现在想查询
A表中所有属性cc不为空的的记录
HQL语句该怎么写?

解决方案 »

  1.   

    from A a jion a.cc 会得到size为2的list,list.get(0)是A的Object[],list.get(1)是B的Object[].
    或者子查询:
    from A a where a.id in (select b.dd.id from a.cc b)没测试,可能有误,你试试看。
      

  2.   

    from A a where a.id in (select b.dd.id from B  b)
      

  3.   

    from A a where a.cc is not null
      

  4.   

    select a from A a
      left join a.cc as b
      where b is not null