JPQL / HQL 获取连接语法与 EclipseLink 和 EclipseLink 兼容休眠
我希望能够在 EclipseLink 和 EclipseLink 之间交换我的 JPA 实现。通过简单的属性更改即可休眠。我可以做到这一点,但导致我出现问题的是命名查询验证。使用 EclipseLink 我必须像这样编写 fetch joins:
SELECT id
FROM IndexDefinition id
JOIN FETCH id.index
JOIN id.index i
JOIN FETCH i.indexVersions
但是当使用 Hibernate 验证此查询时,我得到以下异常:
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
因此我可以将查询更改为 HQL 友好,如下所示:
SELECT id
FROM IndexDefinition id
JOIN FETCH id.index i
JOIN FETCH i.indexVersions
但这会导致 EclipseLink 中出现以下异常:
Exception Description Syntax error parsing the query [IndexDefinition.getForIndex] SELECT id FROM IndexDefinition id JOIN FETCH id.index i, syntax error at [id].
Internal Exception MismatchedTokenException(78!=-1)
我知道我可以在我的 DAO 级别使用查询提示来执行获取连接,但是有没有一种方法可以使用特定的获取连接语法来满足两个 JPA 实现的需要?
I would like to be able to swap my JPA implementation between EclipseLink & Hibernate with a simple property change. I can do this ok but what is causing me problems is the named query validation. Using EclipseLink I have to write fetch joins like so:
SELECT id
FROM IndexDefinition id
JOIN FETCH id.index
JOIN id.index i
JOIN FETCH i.indexVersions
But when validating this query using Hibernate I get the following exception:
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
So I can change the query to be HQL friendly like so:
SELECT id
FROM IndexDefinition id
JOIN FETCH id.index i
JOIN FETCH i.indexVersions
But this then causes the following exception in EclipseLink:
Exception Description Syntax error parsing the query [IndexDefinition.getForIndex] SELECT id FROM IndexDefinition id JOIN FETCH id.index i, syntax error at [id].
Internal Exception MismatchedTokenException(78!=-1)
I know I can use query hints at my DAO level to perform a fetch join but is there a way of pleasing both JPA implementations with a specific fetch join syntax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,JPA 1.0 似乎不支持 嵌套联接。来自 JPA 1.0 规范:
因此,虽然某些 JPA 提供程序可能支持嵌套联接,但其行为并未标准化。
参考
Well, it seems that nested joins are not supported by the JPA 1.0. From the JPA 1.0 specification:
So, while nested joins might be supported by some JPA providers, the behavior is not standardized.
References