在 Hibernate 中将列名用双引号括起来 [英] Wrap column names in double quotes in Hibernate

查看:67
本文介绍了在 Hibernate 中将列名用双引号括起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Spring JPA 2.0.9 和 Hibernate 5.3.5 和 这种方言 使用取自此 分布.

I'm using Spring JPA 2.0.9 with Hibernate 5.3.5 and this dialect to access a FileMaker (v16) database via JDBC using the official JDBC driver taken from this distribution.

问题是生成的 SQL 最终是列名以相应的表名作为前缀,例如:

The thing is that the resulting SQL ends up being with column names prefixed by the respective table names like:

select 
marketingc0_.a__IDPK_MarketingCategory as a__IDPK_1_0_0_, marketingc0_.Active as Active2_0_0_
from MarketingCategories as marketingc0_
where marketingc0_.a__IDPK_MarketingCategory=1

哪个 FileMaker 不接受抱怨错误的语法:

which FileMaker doesn't accect complaining about the wrong syntax:

[08007][27034] [FileMaker][FileMaker JDBC] FQL0001/(1:153):有查询语法错误.

[08007][27034] [FileMaker][FileMaker JDBC] FQL0001/(1:153): There is an error in the syntax of the query.

但是,如果列名像这样用双引号括起来,它会毫无怨言地吞下 SQL:

However it gulps down the SQL without complains if the column names are wrapped in double quotes like this:

select
    marketingc0_."a__IDPK_MarketingCategory" as a__IDPK_1_0_0_, marketingc0_."Active" as Active2_0_0_
    from MarketingCategories as marketingc0_
    where marketingc0_.a__IDPK_MarketingCategory=1

我提出的解决方案是将这些引号包含在实体注释中:

The solution I've come up with is including these quotes into the entity annotations:

public class MarketingCategory {
    @Id
    @Column(name = ""a__IDPK_MarketingCategory"")
    private Integer id;

    @Column(name = ""a_ID_User"")
    private Integer userId;

    @Column(name = ""Active"")
    private Boolean active;

...
}

这看起来不太好.

是否可以将 Hibernate 配置为自动将所有列名括在双引号中?

Is it possible configure Hibernate so that it would wrap all the column names in double quotes automatically?

推荐答案

您可以在定义中将名为 hibernate.globally_quoted_identifiers 的属性设置为 true ,它会引用所有身份标识.除此之外还有一个选项是不引用列,但没有选项只引用列.

You can set a property named hibernate.globally_quoted_identifiers to true in your definitions and it will quote all identifiers. There is an option in addition to that to not quote the columns, but there is no option to only quote the columns.

这篇关于在 Hibernate 中将列名用双引号括起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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