http://www.hibernate.org/hib_docs/reference/zh-cn/html/queryhql.html#queryhql-select
查詢可以返回任何值類型的函數(shù),
select子句選擇在結(jié)果集中返回哪些對象和屬性。思考一下下面的例子:
select mate
from eg.Cat as cat
inner join cat.mate as mate
這個查詢會選擇出作為其它貓(Cat)朋友(mate)的那些貓。當然,你可以更加直接的寫成下面的形式:
select cat.mate from eg.Cat cat
你甚至可以選擇集合元素,使用特殊的elements功能。下面的查詢返回所有貓的小貓。
select elements(cat.kittens) from eg.Cat cat
查詢可以返回任何值類型的屬性,包括組件類型的屬性:
select cat.name from eg.DomesticCat cat
where cat.name like 'fri%'
select cust.name.firstName from Customer as cust
查詢可以用元素類型是Object[]的一個數(shù)組返回多個對象和/或多個屬性。
select mother, offspr, mate.name
from eg.DomesticCat as mother
inner join mother.mate as mate
left outer join mother.kittens as offspr
或者實際上是類型安全的Java對象
select new Family(mother, mate, offspr)
from eg.DomesticCat as mother
join mother.mate as mate
left join mother.kittens as offspr
上面的代碼假定Family有一個合適的構(gòu)造函數(shù)。