gpt4 book ai didi

java - 在 Hibernate 中将列名用双引号引起来

转载 作者:行者123 更新时间:2023-11-29 04:16:05 27 4
gpt4 key购买 nike

我将 Spring JPA 2.0.9 与 Hibernate 5.3.5 和 this dialect 结合使用使用取自此 distribution 的官方 JDBC 驱动程序通过 JDBC 访问 FileMaker (v16) 数据库.

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

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 不接受提示语法错误:

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

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

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

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

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 使其自动将所有列名用双引号引起来?

最佳答案

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

关于java - 在 Hibernate 中将列名用双引号引起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52328876/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com