问题描述
我面临着为使用 MySQL 5.0 而编写的遗留系统,现在需要将其迁移到 MySQL 5.5(要求).我发现有一列名为maxvalue
,这似乎是MySQL 5.5中的系统字.因此,我所有包含此列的 Hibernate 查询都给出了语法错误:
I am faced with legacy system written to work with MySQL 5.0 and now need to migrate it to MysQL 5.5 (requirement). I found that one column was named maxvalue
, which seems to be system word in MySQL 5.5. Thus all my Hibernate queries that include this column give syntax error:
Caused by: java.sql.BatchUpdateException: You have an error in yourSQL 语法;检查与您的 MySQL 服务器相对应的手册'maxvalue
似乎 Hibernate 不会自动而是在字段名称周围反引号 `.如果我提取查询,反引号 `maxvalue`
它在 MySQL 5.5 中正确运行.
It seems that Hibernate does not automatically but backquotes ` around the field name. If I extract the query, backquote `maxvalue`
it runs correctly in MySQL 5.5.
我找到了解决方案 如何为特定字段/表明确强制反引号.问题是我不确定有多少其他列名会产生这样的问题.有没有办法告诉 Hibernate 自动反引用所有表/列名?(这将产生有效的 SQL,我不知道为什么它默认情况下不为 MySQL 这样做).
I have found solution how to explicitly force backquotes for specific field / table. The thing is that I am not sure how many other column names will produce such problem. Is there a way to tell Hibernate to automatically backquote all table/ column names? (which will produce valid SQL and I don't know why it does not do that by default for MySQL).
编辑:这个讨论几乎让我相信我想要的是不可能的.
EDIT: This discussion almost makes me believe that what I want is not possible.
推荐答案
有一个 非文档 用于此目的的属性.使用,
There is a non-documented property for this purpose. Use,
<property name="hibernate.globally_quoted_identifiers" value="true"/>
或
<property name="hibernate.globally_quoted_identifiers">true</property>
这篇关于使休眠反引用所有表/列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!