Few days ago I switched my Java Spring Boot project from Hibernate ORM 6.1.7 to Hibernate ORM 6.2.1. The underlying database is MySQL 8 which supports
enum data type.
In one of my entities I have enum which is annotated by
@Enumerated(EnumType.STRING) and so far it was working as expected -
varchar table column was created by Hibernate few years ago.
spring.jpa.hibernate.ddl-auto = validate
In project configuration I always use
validate just to be sure if and when any changes appear so I could apply those changes to my production database before deploy.
After switching to Hibernate ORM 6.2.1 this table column was converted to MySQL’s
enum data type which is okay with me. I just have to upgrade my production database with:
ALTER TABLE `custom_currency` MODIFY COLUMN `sign_position` enum( 'AFTER_NO_SPACE', 'AFTER_WITH_SPACE', 'BEFORE_NO_SPACE', 'BEFORE_WITH_SPACE' ) COLLATE utf8mb4_unicode_ci DEFAULT NULL;
When I try to start my app with
spring.jpa.hibernate.ddl-auto set to
validate - exception is thrown:
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [sign_position] in table [custom_currency]; found [enum (Types#CHAR)], but expecting [varchar(255) (Types#VARCHAR)]
If I change
ddl-auto setting to
none, the table column of
enum type stays as it is and application can boot up.
- spring.jpa.hibernate.ddl-auto = update
- run the app
- database is updated
- stop the app
- spring.jpa.hibernate.ddl-auto = validate
- run the app
- exception is thrown
Am I doing something wrong? Or is it really a bug?