Red Hat Training

A Red Hat training course is available for Red Hat JBoss Web Server

8.4. select 句

select 句は、クエリ結果セットで返すオブジェクトとプロパティを取得します。以下のことに留意してください。
select mate 
from Cat as cat 
    inner join cat.mate as mate
クエリは 他のCatmate を選択します。実際には、このクエリを以下のようにもっとコンパクトに記述できます。
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 (HQL 固有の機能) として返すことができます。
select new list(mother, offspr, mate.name)
from DomesticCat as mother
    inner join mother.mate as mate
    left outer join mother.kittens as offspr
または実際のタイプセーフ Java オブジェクトとして返すことができます。
select new Family(mother, mate, offspr)
from DomesticCat as mother
    join mother.mate as mate
    left join mother.kittens as offspr
クラス Family が適切なコンストラクトを持っていると見なします。
as を使用して、選択された式にエイリアスを割り当てることができます。
select max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n
from Cat cat
これは、select new map (HQL 固有の機能) とともに使用する場合に最も役に立ちます。
select new map( max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n )
from Cat cat
このクエリは、エイリアスからの Map を選択された値に返します。