【问题标题】:Basic SpringBoot application throwing schema validation error基本 Spring Boot 应用程序抛出模式验证错误
【发布时间】:2020-11-24 11:38:42
【问题描述】:

我在运行 SpringBoot 应用程序时遇到异常:

原因:org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: 在表 [my_table] 的列 [id] 中遇到错误的列类型;找到 [int (Types#INTEGER)],但期待 [bigint (Types#BIGINT)]

下面是我的实体类中 id 的列定义:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

在数据库端,该列的创建方式类似于

`id` int(11) NOT NULL AUTO_INCREMENT,

有人可以帮忙解决这个问题吗?

【问题讨论】:

  • 根据错误消息告诉您的内容,您需要将 DB 列更改为 BIGINT 或将实体类更改为使用 Integer 而不是 Long 作为 id 字段。

标签: mysql spring-boot hibernate jpa


【解决方案1】:

引起:org.hibernate.tool.schema.spi.SchemaManagementException: 架构验证:在 [id] 列中遇到错误的列类型 表 [my_table]; 找到 [int (Types#INTEGER)],但期待 [bigint (类型#BIGINT)]

如突出显示的那样,列 id 是一种 INTEGER,我们在实体中指定了 Long(BIGINT for DB)。导致错误消息的数据类型不匹配。

你可以change the database column type从INTEGER转BIGINT

ALTER TABLE tablename MODIFY columnname columntype;

如果您没有编写任何 SQL 来初始化数据库。您可以使用 hibernate 属性如下

hibernate.hbm2ddl.auto=create or update

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 2019-09-16
    • 2017-09-18
    • 2016-07-30
    • 1970-01-01
    • 2021-09-14
    • 2018-01-29
    相关资源
    最近更新 更多