"无效的ORDER BY表达式"使用HSQLDB和Hibernate

时间:2015-03-24 02:12:00

标签: hibernate hsqldb

我正在使用Hibernate 4.1.7

访问嵌入式HSQLDB 2.3.2数据库

这是我的HQL查询

FROM RunE x  ORDER BY x.startedAt

这是由Hibernate生成的SQL,由于将 hibernate.show_sql 配置为 true

,因此在控制台上显示
select
    rune0_.ID as ID6_,
    rune0_.FINISHED_AT as FINISHED2_6_,
    rune0_.PERCENT_COMPLETE as PERCENT3_6_,
    rune0_.PROBLEM as PROBLEM6_,
    rune0_.PROC_PARAMS as PROC7_6_,
    rune0_.PROCESSOR as PROCESSOR6_,
    rune0_.RUN_TYPE as RUN4_6_,
    rune0_.STARTED_AT as STARTED5_6_
from
    ZA_RUN rune0_
order by
    rune0_.STARTED_AT

最终原因异常来自HSQLDB,并且是:

Caused by: org.hsqldb.HsqlException: invalid ORDER BY expression
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.QuerySpecification.resolveColumnRefernecesInOrderBy(Unknown Source)
    at org.hsqldb.QuerySpecification.resolveColumnReferences(Unknown Source)
    at org.hsqldb.QuerySpecification.resolveReferences(Unknown Source)
    at org.hsqldb.QueryExpression.resolve(Unknown Source)
    at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
    at org.hsqldb.Session.compileStatement(Unknown Source)
    at org.hsqldb.StatementManager.compile(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)

根据HSQLDB manual,查询的语法看起来很好。我还尝试使用SQL Workbench/J和它编译并运行的相同的hsqldb-2.3.2.jar库,但是在使用Hibernate时失败了。

作为进一步的测试,我从我的HQL中删除了ORDER BY x.startedAt,从而产生了SQL

select
    rune0_.ID as ID6_,
    ...
    rune0_.STARTED_AT as STARTED5_6_
from
    ZA_RUN rune0_

它运行正常,所以它似乎与ORDER BY子句有关。

0 个答案:

没有答案