Red Hat Training
A Red Hat training course is available for Red Hat JBoss Web Server
15.6. Select 節
select
節は、どのオブジェクトと属性をクエリ結果に返すかを選択します。以下を考えて見ましょう。
select mate from Cat as cat inner join cat.mate as mate
クエリは他の
Cat
の mate
を選択します。実際には次のように、より簡潔に表現できます:
select cat.mate from Cat cat
クエリはコンポーネント型のプロパティを含む、あらゆる値型のプロパティも返せます:
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
もしくは
List
として:
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 オブジェクトとして:
select new Family(mother, mate, offspr) from DomesticCat as mother join mother.mate as mate left join mother.kittens as offspr
選択した表現に
as
を使って別名をつけることもできます:
select max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n from Cat cat
select new map
と一緒に使うときに最も役立ちます:
select new map( max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n ) from Cat cat
このクエリは別名から select した値へ
Map
を返します。