【问题标题】:Hibernate - Raw Query execution_KEY Words Issue in query?Hibernate - 原始查询执行_关键字查询中的问题?
【发布时间】:2013-06-06 18:15:06
【问题描述】:

设置由 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,则为子查询中的多选。

请指教。任何建议都会有很大帮助。

【问题讨论】:

    标签: sql hibernate keyword


    【解决方案1】:

    来自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]')转义您的字段。

    【讨论】:

    • 谢谢亚历克斯。但我尝试了以下选项 [Key] 、 [Key] 、 "[key]" 、 "key" 没有任何效果。它看起来很疯狂,但尝试了所有这些。由于其他应用程序中代码更改的连锁反应,无法更改列名。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    相关资源
    最近更新 更多