【问题标题】:Hibernate 4.3.0 XML Mapping Escape Characters ExceptionHibernate 4.3.0 XML 映射转义字符异常
【发布时间】:2014-02-09 19:06:10
【问题描述】:

在我的User.hbm.xml 我有:

<property name="delete" type="java.lang.String">
      <column name="`delete`" />
</property>

我也尝试过 ''[] 但都给出了相同的例外:

org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions

ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"delete"

如果我将列名从 delete 更改为 deletea,那么它可以工作,所以我知道它没有正确转义列名。

【问题讨论】:

    标签: java mysql sql xml hibernate


    【解决方案1】:

    您可以尝试将此属性设置为自动引用所有标识符:

    hibernate.globally_quoted_identifiers=true
    

    【讨论】:

    • MySQL Server 5.6 的 Hibernate 使用的语法似乎存在问题。根据 MySQL 服务器,Hibernate 将 "double quotes" 放在所有无效语法的周围...
    • 你设置hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect了吗?
    【解决方案2】:

    试着改变这个

    <column name="`name`" />
    

    到这里

    <column name="name" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-11
      • 2018-02-24
      • 2020-04-01
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多