【问题标题】:JPQL - combine multiple fields in the IN expressionJPQL - 在 IN 表达式中组合多个字段
【发布时间】:2012-01-22 13:02:14
【问题描述】:

我想知道是否有一种方法可以编写类似于下面的 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)

感谢任何帮助。

谢谢, 吉隆坡

【问题讨论】:

    标签: jpa eclipselink jpql


    【解决方案1】:

    JPA 规范未涵盖此类查询(1 和 2 均未涵盖)。但是,Hibernate 确实支持它。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-08
        • 2011-09-17
        • 2018-06-16
        • 2020-01-29
        • 1970-01-01
        • 2023-03-29
        相关资源
        最近更新 更多