【问题标题】:Special character in table name hibernate giving error表名中的特殊字符休眠给出错误
【发布时间】:2016-03-08 00:23:21
【问题描述】:

我正在尝试从 Hibernate 更新表。我的表名在名称的开头有特殊字符“@”。当我尝试更新它时,它给了我以下错误。

严重:servlet [kendo] 在路径 [/GanttView] 的上下文中的 Servlet.service() 引发异常 [请求处理失败;嵌套异常是 org.hibernate.QueryException: unexpected char: '@' [Update [@IS_Demand] set sel=1]] 根本原因 org.hibernate.QueryException: 意外字符: '@' [更新 [@IS_Demand] set sel=1]

我不想更改数据库中表的名称,因为那样我将不得不更改很多东西。有什么办法可以访问它。 我尝试了许多其他组合,例如

\"@IS_Demand\"  or  '@IS_Demand' or '[@IS_Demand]'

有人知道答案吗?

【问题讨论】:

标签: java mysql hibernate


【解决方案1】:

尝试使用转义字符

\\@IS_Demand

!@IS_Demand

【讨论】:

    【解决方案2】:

    您需要设置一个可用的属性。

    <property name="hibernate.globally_quoted_identifiers" value="true"/>
    

    更多详情,

    AvailableSettings.html#GLOBALLY_QUOTED_IDENTIFIERS

    【讨论】:

    • 非常感谢 Ankur-singhal 我会尝试使用它
    • 我刚才试过了,但它不起作用。我正在使用休眠 4.1.7。
    【解决方案3】:

    设置属性hibernate.globally_quoted_identifiers=true

    【讨论】:

      猜你喜欢
      • 2010-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-25
      相关资源
      最近更新 更多