// 用於快速翻閱 安全
select 子句選擇將哪些對象與屬性返回到查詢結果集中。考慮以下狀況: 函數
select mate from Cat as cat inner join cat.mate as mate
該語句將選擇其它 Cat 的 mate(其餘貓的配偶)。實際上,你能夠更簡潔的用如下的查詢語句表達相同的含義: spa
select cat.mate from Cat cat
查詢語句能夠返回值爲任何類型的屬性,包括返回類型爲某種組件(Component)的屬性: code
select cat.name from DomesticCat cat where cat.name like 'fri%'
select cust.name.firstName from Customer as cust
查詢語句能夠返回多個對象和(或)屬性,存放在 Object[] 隊列中, 對象
select mother, offspr, mate.name from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr
select new list(mother, offspr, mate.name) from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr
假設類 Family 有一個合適的構造函數 - 做爲實際的類型安全的 Java 對象: it
select new Family(mother, mate, offspr) from DomesticCat as mother join mother.mate as mate left join mother.kittens as offspr
你能夠使用關鍵字 as 給「被選擇了的表達式」指派別名: class
select max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n from Cat cat
這種作法在與子句 select new map 一塊兒使用時最有用: List
select new map( max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n ) from Cat cat