javapostgresqlhibernatejpaliquibase

SpringBoot: Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory


In my Postgres database i have created the schema named pet and ran liquibase migration to create schema, tables and types but while starting my spring boot application.

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,
);

in my spring boot this is the jpa configurations.

  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=unspecified

other information. Postgres Version: PostgreSQL 14.6 on aarch64-unknown-linux-gnu, compiled by aarch64-unknown-linux-gnu-gcc (GCC) 7.4.0, 64-bit Java Version: 17 Hibernate: hypersistence-utils-hibernate-62 3.6.1

Has anyone encountered this error before?

Tried changing @Column(name = "pet_type", nullable = false, columnDefinition = "pet_type") to @Column(name = "pet_type", nullable = false, columnDefinition = "pet.pet_type")


Solution

  • The issue was missing privilege for the database user for pet schema.