JPQL - 在 IN 表达式中组合多个字段

发布于 2024-12-21 19:30:27 字数 730 浏览 2 评论 0原文

我想知道是否有一种方法可以编写类似于下面的JPQL语句类似

select o from entity1 o where (o.field1, o.field2) IN (select value1, value2 from ...)

的sql查询在Oracle 10g中工作。但是,在 eclipselink 中,我收到此错误:

syntax error at [,].
Internal Exception: MismatchedTokenException(81!=84)
at org.eclipse.persistence.exceptions.JPQLException.syntaxErrorAt(JPQLException.java:362)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.handleRecognitionException(JPQLParser.java:301)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.addError(JPQLParser.java:242)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.reportError(JPQLParser.java:359)

感谢任何帮助。

谢谢, 吉隆坡

I am wondering if there is a way to write a JPQL statement similar to the one below

select o from entity1 o where (o.field1, o.field2) IN (select value1, value2 from ...)

The similar sql query works in Oracle 10g. However, in eclipselink, I got this error:

syntax error at [,].
Internal Exception: MismatchedTokenException(81!=84)
at org.eclipse.persistence.exceptions.JPQLException.syntaxErrorAt(JPQLException.java:362)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.handleRecognitionException(JPQLParser.java:301)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.addError(JPQLParser.java:242)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.reportError(JPQLParser.java:359)

Any help is appreciated.

Thanks,
KL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软糯酥胸 2024-12-28 19:30:27

JPA 规范未涵盖此类查询(1 或 2 均不包括)。然而,Hibernate 确实支持它。

This kind of query is not covered by the JPA specification (neither 1 nor 2). However, Hibernate does support it.

笔落惊风雨 2024-12-28 19:30:27

为此,您可以使用本机 SQL 查询,或者可以使用联接而不是子选择。

EclipseLink 在表达式查询中确实支持此功能,但目前在 JPQL 中尚不支持。
(但并非所有数据库都支持这一点)

You can use a native SQL query for this, or perhaps use a join instead of a subselect.

EclipseLink does support this in Expression queries, but not currently in JPQL.
(not all databases support this though)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文