如何使用hql在hibernate中获得具有不同列的整行?

时间:2014-10-04 06:57:16

标签: hibernate hql distinct

table-test的名称

Id      Name      Profession
1        a         Engg
2        b         Engg
3        c         Doctor
4        d         Doctor

期望的输出:

 Id      Name      Profession
 1        a         Engg
 4        d         Doctor

我想获得包含独特专业的行,如上表所示。我试过了

hql-

  

"从测试中选择不同的职业"

它正在返回String行业。我怎样才能获得整排?

1 个答案:

答案 0 :(得分:2)

DISTINCT将仅返回具有唯一值的列。

而不是:

select distinct profession from test

使用以下hql查询:

select * from test group by profession