JPQL中的索引元素访问 [英] Indexed element access in JPQL

查看:71
本文介绍了JPQL中的索引元素访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在JPQL中执行索引元素访问,如 HQL

Is it possible to do indexed element access in JPQL like in HQL :

select o from Order o where o.items[0].id = 1234

我无法在JPA 2规范中找到相关内容,

I couldn't find something related in the JPA 2 specs,

我在这里定位 EclipseLink JPA ,所以如果您出现使用EclipseLink解决方案也是可以的,尽管JPQL标准解决方案是首选。

I am targeting EclipseLink JPA here, so if you come up with an EclipseLink solution, that's ok as well, although a JPQL standard solution is preferred.

推荐答案

INDEX函数应该做到这一点(实际上我测试了它,它确实如此):

The INDEX function should do the trick (actually I tested it and it does):

SELECT o
FROM Order o JOIN o.items i
WHERE i.id = 1234
AND INDEX(i) = 0

JPA 2.0规范( 4.6.17.2.2算术函数):

From the JPA 2.0 specification (4.6.17.2.2 Arithmetic Functions):


INDEX函数返回一个整数
值,它对应于
其参数在有序列表中的位置。
INDEX函数只能应用于
标识变量,这些标识变量表示
类型,其中已经指定了一个订单列

The INDEX function returns an integer value corresponding to the position of its argument in an ordered list. The INDEX function can only be applied to identification variables denoting types for which an order column has been specified.

这篇关于JPQL中的索引元素访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆