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

查看:399
本文介绍了如何在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'.

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

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.

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

Found my answer here Special character in table name hibernate giving error

并在此处找到所有可用的设置 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天全站免登陆