Using Spring Boot 3.2.2 and associated versions (Hibernate 6.4) on Postgres
I have the following java
public enum AddressType{
HOME,
WORK,
SCHOOL;
}
and used in an @Entity class
@Enumerated(EnumType.STRING)
@JdbcTypeCode(SqlTypes.NAMED_ENUM)
private AddressType type;
With the following sql schema
CREATE TYPE address_type AS ENUM('HOME','WORK','SCHOOL');
used in a normal table as
CREATE TABLE IF NOT EXISTS address (
id int8 NOT NULL,
create_date timestamp NULL,
postal_code text NULL,
street1 varchar(100) NULL,
street2 varchar(100) NULL,
country int8 NULL,
state int8 NULL,
**"type" address_type NULL,**
CONSTRAINT address_pkey PRIMARY KEY (id)
);
However, the schema cannot load and validate using this configuration with the following error:
Schema-validation: wrong column type encountered in column [type] in table [address]; found ["address_type" (Types#VARCHAR)], but expecting [type (Types#NAMED_ENUM)]
I cannot find any documentation indicating that there is an alternate way to declare the enumerator. If i keep @Enumerated(EnumType.STRING)
and remove the JDBC Type annotation it does validate and boot but I havenāt tested to see if that really does what we want (and Iām inclined to believe it does not).
Using @JdbcType(PostgreSQLEnumJdbcType.class)
. instead also gives me an identical error.
Any help is appreciated.