【问题标题】:Hibernate 5 - naming strategy - explicit names - capital letters are ignoredHibernate 5 - 命名策略 - 显式名称 - 大写字母被忽略
【发布时间】:2016-09-03 09:27:21
【问题描述】:

我尝试设置我的 JPA 映射。由于某些原因,我必须拥有相同的 java 变量/表列名(包括大写字母),但我无法设置休眠。我尝试使用明确的列名:

@Type(type="java.lang.Integer")
@Column(name = "nextInvoiceNr")
public int nextInvoiceNr;

并带有隐式映射:

@Type(type="java.lang.Integer")
public int nextInvoiceNr;

这两种方法都创建不带大写字母的列名 - “nextinvoicenr”。

我还尝试更改休眠配置添加:

lConf.setProperty("hibernate.implicit_naming_strategy", "org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl");
lConf.setProperty("hibernate.physical_naming_strategy", "org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl");

但没有成功

【问题讨论】:

  • 这似乎有点奇怪,因为我做的最后一件事是编写一些代码将大写名称转换为小写。你身边有没有实现ImplicitNamingStrategyPhysicalNamingStrategy的东西。

标签: hibernate jpa


【解决方案1】:

我刚刚回答了这个问题可能是very similar question,它涉及在 Hibernate 的列名中使用连字符导致的错误。此处可能适用的解决方案是在引号中转义列名:

@Type(type="java.lang.Integer")
@Column(name = "\"nextInvoiceNr\"")
public int nextInvoiceNr;

如果您使用的是 JPA 1.0,那么您可以在反引号中转义列名:

@Column(name = "`nextInvoiceNr`")

当然,替代方法是不依赖区分大小写的列名。

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 2016-01-11
    • 2015-11-16
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    • 2017-01-02
    相关资源
    最近更新 更多