【问题标题】:Missing table error after moving to Hibernate 5.2迁移到 Hibernate 5.2 后丢失表错误
【发布时间】:2018-04-15 04:59:03
【问题描述】:

将休眠升级到 5.2.10 版后,我的 Spring Boot (1.4) 应用程序出现以下错误:

原因:org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [abc.DummyPojoClass]

Java 类是这样的:

@Entity
@Table(schema = "abc", name = "DummyPojoClass")
public class DummyPojoClass  {

    @Column(name = "object_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    private Long objectId;

    @Column(name = "name")
    @Value
    private String name;
}

在数据库中的表是 abc.dummypojoclass,在 Hibernate 4.3 上解析表名没有问题。我试图在 app.properties 中更改命名策略设置:

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

但这没有帮助。任何想法如何解决问题?

【问题讨论】:

  • 你可以尝试将name = "DummyPojoClass" 到name = "dummypojoclass" 在@Table 注释中

标签: postgresql hibernate spring-boot naming


【解决方案1】:

PhysicalNamingStrategyStandardImpl 什么都不做。您可以扩展该策略并将表名转换为小写。

public class LowerCasePhysicalNamingStrategy extends PhysicalNamingStrategyStandardImpl {

    @Override
    public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
        return context.getIdentifierHelper()
                .toIdentifier(name.getText().toLowerCase());
    }

}

如果您需要除转换为小写之外的其他内容,您可能需要更改此策略。

【讨论】:

  • 那么在 Hibernate 5.x 中发生了什么变化,这在 4.3 版中运行良好?
  • @bojek 如果你没有为 Hibernate 4 使用任何命名策略——什么都没有(除了约束的名称)。
猜你喜欢
  • 1970-01-01
  • 2018-07-02
  • 2021-09-25
  • 2013-07-27
  • 1970-01-01
  • 2019-02-03
  • 1970-01-01
  • 2016-02-17
  • 2020-09-04
相关资源
最近更新 更多