Hibernate - 查询中的Raw Query execution_KEY单词问题?

时间:2013-06-06 18:15:07

标签: sql hibernate keyword

设置包含Hibernate 3.我试图按原样执行原始查询。该设置适用于其他简单查询,db插入&更新。

有问题的查询是:

   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 ]

资源就是表格和表格。在hibernate.cfg.xml中有映射设置

  1. 我认为“KEY”是其中一个无法更改的列的名称。我如何逃避关键词?

  2. 如果不是1,则在子查询中进行多选。

  3. 请指教。任何建议都有很大的帮助。

1 个答案:

答案 0 :(得分:0)

来自here

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]')来逃避字段。