如何在JPA中映射名称为保留字的实体字段 [英] How to map an entity field whose name is a reserved word in JPA

查看:40
本文介绍了如何在JPA中映射名称为保留字的实体字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Column(name="open")

在休眠状态下使用 sqlserver 方言.

Using sqlserver dialect with hibernate.

[SchemaUpdate] Unsuccessful: create table auth_session (id numeric(19,0) identity not null, active tinyint null, creation_date datetime not null, last_modified datetime not null, maxidle int null, maxlive int null, open tinyint null, sessionid varchar(255) not null, user_id numeric(19,0) not null, primary key (id), unique (sessionid))
[SchemaUpdate] Incorrect syntax near the keyword 'open'.

我希望 hibernate 在创建表时使用带引号的标识符.

I would have expected hibernate to use quoted identifier when creating the table.

关于如何处理这个问题的任何想法......除了重命名字段?

Any ideas on how to handle this... other than renaming the field?

推荐答案

有同样的问题,但有一个名为 Transaction 的表名.如果你设置

Had the same problem, but with a tablename called Transaction. If you set

hibernate.globally_quoted_identifiers=true

然后将引用所有数据库标识符.

Then all database identifiers will be quoted.

在这里找到我的答案表名中的特殊字符hibernate给出错误

并在此处找到所有可用设置https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/appendices/Configurations.html

And found all available settings here https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/appendices/Configurations.html

虽然找不到更好的文档.

Could not find better docs for this though.

就我而言,设置在我的 Spring 属性文件中.正如评论中提到的,它也可能在其他与休眠相关的配置文件中.

In my case the setting was in my Spring properties file. As mentioned in the comments, it could also be in other, hibernate related, configuration files.

这篇关于如何在JPA中映射名称为保留字的实体字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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