Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

13.4.8. 修飾パス式について

これまでは、コレクション値関連づけは、コレクションのを実際に参照していると言及されました。コレクションのタイプによっては、明示的な修飾式のセットも利用できます。

表13.9 修飾パス式

Description
VALUE
コレクション値を参照します。修飾子を指定しないのと同じです。意図を明示的に表示するのに役立ちます。いずれかのタイプのコレクションと値の参照に有効です。
INDEX
HQL ルールによると、これはマップとリストの両方で有効です。 javax.persistence.OrderColumn マップキーまたはリスト位置 (別名 OrderColumn 値) を参照するための注釈。ただし、JPQL はこれを List ケースで使用するために予約し、MAP ケースに KEY を追加します。JPA プロバイダーの移植性に関心のあるアプリケーションは、この区別を認識する必要があります。
KEY
Maps にのみ有効です。マップのキーを参照します。キー自体がエンティティーである場合は、さらに移動することができます。
ENTRY
Maps にのみ有効です。マップの論理を参照します java.util.Map.Entry タプル (キーと値の組み合わせ)。ENTRY はターミナルパスとしてのみ有効で、選択でのみ有効です。

例13.9 適格なコレクションの参照

// Product.images is a Map<String,String> : key = a name, value = file path

// select all the image file paths (the map value) for Product#123
select i
from Product p
    join p.images i
where p.id = 123

// same as above
select value(i)
from Product p
    join p.images i
where p.id = 123

// select all the image names (the map key) for Product#123
select key(i)
from Product p
    join p.images i
where p.id = 123

// select all the image names and file paths (the 'Map.Entry') for Product#123
select entry(i)
from Product p
    join p.images i
where p.id = 123

// total the value of the initial line items for all orders for a customer
select sum( li.amount )
from Customer c
        join c.orders o
        join o.lineItems li
where c.id = 123
  and index(li) = 1