4.5. 关于限定路径表达式
之前已指出收集值的关联实际指的是该集合的值。根据集合的类型,也提供一组明确的资格表达式。
| expression | 描述 |
|---|---|
|
| 指的是集合值。与未指定限定符相同。用于明确显示意图.对任何类型的 collection-valued 引用有效。 |
|
|
根据 HQL 规则,这对于指定 javax.persistence.OrderColumn 注解的 Map 和 Lists 都有效,以引用 Map 键或 List 位置(回答 OrderColumn 值)。但是,Java Persistence 查询语言保留在 List 案例中使用,并为 MAP 案例添加 |
|
| 仅对映射有效。指地图的密钥。如果密钥本身是一个实体,可以进一步导航。 |
|
|
仅对映射有效。引用 Map 的逻辑 java.util.Map.Entry tuple(其键和值的组合)。 |
示例:限定集合参考
// 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