Hibernate - Raw查询execution_关键词查询问题



设置包含Hibernate 3。我试图执行原始查询,因为它是。该设置适用于其他简单查询,数据库插入&更新。

问题中的查询是:

   org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 29 [
          SELECT keyMain, value FROM (select distinct K.[key] as keyMain,
            ( SELECT value FROM com.trans.dto.Resources as L WHERE L.[key] = K.[key] 
              and L.lang_code = 'A11' ) as value from com.trans.dto.Resources as  K ) 
              as test order by keyMain ]

Resources是表&在hibernate.cfg.xml

中设置映射
  1. 我以为"KEY"是其中一个不能更改的列的名称。如何转义关键字

  2. 如果不为1,则为子查询中的多选择。

请建议。任何建议都很有帮助。

从这里:

You can force Hibernate to quote an identifier in the generated SQL
by enclosing the table or column name in backticks in the mapping document. 
Hibernate will use the correct quotation style for the SQL Dialect. 
This is usually double quotes, but the SQL Server uses brackets and MySQL uses backticks.

因此,请尝试用双引号或方括号('[key]')转义您的字段。

最新更新