4.5. 修飾パス式について
これまでは、コレクション値関連づけは、コレクションの値を実際に参照していると言及されました。コレクションのタイプによっては、明示的な修飾式のセットも利用できます。
表4.2 修飾パス式
式 | 説明 |
---|---|
| コレクション値を参照します。修飾子を指定しないのと同じです。意図を明示的に表示するのに役立ちます。いずれかのタイプのコレクションと値の参照に有効です。 |
|
HQL ルールによると、これは、javax.persistence.OrderColumn アノテーションを指定して Map キーまたは List の場所 (別名 OrderColumn 値) を参照する Maps と List の両方に対して有効です。ただし、Java Persistence クエリー言語は、これを List ケースで使用するために予約し、MAP の場合に |
| Maps にのみ有効です。マップのキーを参照します。キー自体がエンティティーである場合は、さらに移動することができます。 |
|
Maps にのみ有効です。Map の論理 java.util.Map.Entry タプル (キーと値の組み合わせ) を参照します。 |
例: 修飾コレクション参照
// 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