JPQL - 在 IN 表达式中组合多个字段
我想知道是否有一种方法可以编写类似于下面的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JPA 规范未涵盖此类查询(1 或 2 均不包括)。然而,Hibernate 确实支持它。
This kind of query is not covered by the JPA specification (neither 1 nor 2). However, Hibernate does support it.
为此,您可以使用本机 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)