使hibernate反引号所有表/列名 [英] Make hibernate backquote all table / column names
问题描述
我面临着使用MySQL 5.0编写的遗留系统,现在需要将其迁移到MysQL 5.5(要求)。我发现一列被命名为 maxvalue
,这似乎是MySQL 5.5中的系统字。因此,我所有包含此列的Hibernate查询都提供语法错误:
导致:java.sql.BatchUpdateException:您的
附近使用正确的语法
SQL语法;检查对应于您的MySQL服务器
版本的手册,以使用'maxvalue
似乎Hibernate不会自动但反向引用字段名称。如果我提取查询,请反引号`maxvalue \
它在MySQL 5.5中正确运行。
解决方案如何明确强制反引号对于特定的字段/表。事实是,我不知道有多少其他列名将产生这样的问题。 有没有办法告诉Hibernate自动反引用所有的表/列名?(这将产生有效的SQL,我不知道为什么MySQL默认不这样做)。 >
编辑:这个讨论几乎让我相信我想要的是不可能的。
有一个没有记录的属性为此目的:
< property name =hibernate.globally_quoted_identifiersvalue =true />
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 your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'maxvalue
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.
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:
<property name="hibernate.globally_quoted_identifiers" value="true"/>
这篇关于使hibernate反引号所有表/列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!