我如何在一个名为hibernate的密钥列名称中加入反引号 [英] How do I put backticks in a column name called key for hibernate

查看:152
本文介绍了我如何在一个名为hibernate的密钥列名称中加入反引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MySQL数据库表,我无法修改但必须插入值。它有一个名为 key 的列,我需要插入它。



现在,我的.hbm.xml文件包含:

 < ; property name =key
type =string
column =key/>

生成的插入查询失败。在添加[key]时,生成的SQL现在包含,但这也失败了。在检查MYSQL Workbench时,我发现 key 可以工作。



但是,如果我在文件如上所述,当使用[键]时,它回到键。有人可以指导我如何添加 key 并实现所需的插入操作吗?

解决方案

这里有一个hibernate配置选项。它需要Hibernate 3.5,我不确定你是否使用hbm文件。

在你的hibernate配置集中

  hibernate.globally_quoted_identifiers = true 

环境配置列表此处

I have a MySQL DB table which I cannot modify but have to insert values into. It has a column called key which I need to insert into.

Now, my .hbm.xml file has:

    <property name="key"
          type="string"
          column="key" />

The insert query generated hence fails. On adding [key], the generated SQL now contained key but this also failed. On checking in MYSql Workbench, I found that key can work.

However, if I change this in the file mentioned above, it reverts to the "key" as when using [key]. Can someone guide me as to how I can add key and bring about the required insert?

解决方案

There is a hibernate configuration option for this. It needs Hibernate 3.5 which I'm not sure if you're using based on your use of hbm files.

In your hibernate config set

hibernate.globally_quoted_identifiers=true

List of environment config is here

这篇关于我如何在一个名为hibernate的密钥列名称中加入反引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆