HQL中这样写对吗?select distinct stu,tea,cou from Student as stu,Teacher as tea,Course as cou where ......

解决方案 »

  1.   

    hql语句貌似不能用distinct ,跟sql还是有区别的
      

  2.   

    hql可以使用distinct,问题是你同时查询出3个对象出来做什么???你是不是想要:
    select distinct stu.id,tea.name,cou.code from Student as stu,Teacher as tea,Course as cou where ......这样的东西???
      

  3.   

    从来没这样写过HQL   你这样写,效率还不慢死啊。
      

  4.   

    为什么不利用Hibernate对象之间的关系呢,这种写法跟SQL语句区别不大,没利用ORM的好处
      

  5.   

    不能用distinct,我测试过了!之前我也遇到这样的问题!
      

  6.   

    放弃HQL 用executeSQLQuery 执行SQL  自己封装VO
      

  7.   


    Hibernate 3.2 API 中明确说明了 是支持 distinct 的
    楼主的写法应该是报错的,并且不会被广大 码农 们所接受如果你只是想显示三个实体的部份数据
    可以重新定义一个类 或 者 使用 三个类中的一个来封装数据
    假设在 stu 中先定义要接收的 数据字段,
    那么可以 在stu 中新定义 teaName,teaSex,couName 等,可以不用映射
    在 stu 中添加新的构造函数,stu(String stuName,stuSex,teaName,teaSex,couName ){....}在 hql 查询的时候就可以写成:
    SELECT com.companyName,stu(distinct stu.name, stu.sex, tea.name, tea.sex, cou.name) From Student as stu,Teacher as tea,Course as cou WHERE ......
    那么查询出来的数据会被直接封装成 stu 对象集合里
      

  8.   

    稍微更正一下,我上面写的语句
    SELECT distinct com.companyName,stu(stu.name, stu.sex, tea.name, tea.sex, cou.name) From Student as stu,Teacher as tea,Course as cou WHERE ......
      

  9.   

    怎么不直接用sql  用hql 还得 转换对象  碰到 海量多张表联查的数据  不的等死啊