在我的 Postgres 数据库中,我创建了名为 pet 的模式,并运行 liquibase 迁移来创建模式、表和类型,但在启动我的 Spring Boot 应用程序时。
Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [pet_type] in table [pets]; found ["pet"."pet_type" (Types#VARCHAR)], but expecting [pet_type (Types#OTHER)]
PetEntity.java
@Enumerated(EnumType.STRING)
@Type(PostgreSQLEnumType.class)
@Column(name = "pet_type", nullable = false, columnDefinition = "pet_type")
private PetType petType;
SQL
CREATE TYPE pet_type AS ENUM ('REPTILES', 'FERRETS');
CREATE TABLE pets
(
id UUID NOT NULL,
pet_type PET_TYPE NOT NULL,
);
在我的 Spring Boot 中,这是 jpa 配置。
jpa:
generate-ddl: true
hibernate:
ddl-auto: validate
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
default_schema: pet
url:jdbc:postgresql://localhost:5432/postgres?currentSchema=pet&stringtype=未指定
其他信息。 Postgres 版本: aarch64-unknown-linux-gnu 上的 PostgreSQL 14.6,由 aarch64-unknown-linux-gnu-gcc (GCC) 7.4.0 编译,64 位 Java 版本: 17 休眠: hypersistence-utils-hibernate-62 3.6.1
有人遇到过这个错误吗?
尝试将@Column(name =“pet_type”,nullable = false,columnDefinition =“pet_type”)更改为@Column(name =“pet_type”,nullable = false,columnDefinition =“pet.pet_type”)
问题在于数据库用户缺少
pet
架构的权限。