4.5. 关于限定路径表达式


之前已指出收集值的关联实际指的是该集合 的值。根据集合的类型,也提供一组明确的资格表达式。

Expand
表 4.2. 路径表达式
expression描述

VALUE

指的是集合值。与未指定限定符相同。用于明确显示意图.对任何类型的 collection-valued 引用有效。

INDEX

根据 HQL 规则,这对于指定 javax.persistence.OrderColumn 注解的 Map 和 Lists 都有效,以引用 Map 键或 List 位置(回答 OrderColumn 值)。但是,Jakarta Persistence 查询语言保留在列表案例中使用,并为 MAP 案例添加 KEY。对 Jakarta Persistence 提供商可移植性感兴趣的应用应了解这一区别。

KEY

仅对映射有效。指地图的密钥。如果密钥本身是一个实体,可以进一步导航。

ENTRY

仅对映射有效。引用 Map 的逻辑 java.util.Map.Entry tuple(其键和值的组合)。ENTRY 仅作为终端路径有效,且仅在 select 子句中有效。

示例:限定集合参考

// 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
Copy to Clipboard Toggle word wrap

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat