Open
Description
Overview of the issue
When Hibernate schema validation is on, the application or tests fail when an enum is used in an entity with MySQL.
Motivation for or Use Case
JHipster generated codes should pass schema validation.
Reproduce the error
- Create a new project with MySQL
- Create an entity which contains an ENUM
- Update
src/test/resources/config/application-testdev.yml
to usespring.jpa.hibernate.ddl-auto=validate
andspring.jpa.properties.hibernate.hbm2ddl.auto=validate
. Don't know why two entries for the same thing! - Execute IT tests using
./mvnw clean verify
- You will see an error similar to the following
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [provider] in table [third_party_providers]; found [varchar (Types#VARCHAR)], but expecting [enum ('sample_provider') (Types#ENUM)]
Related issues
Suggest a Fix
Hibernate documentation, 3.11. Enumerated types clearly states that even @Enumerated(STRING)
is used, it will still map to ENUM column type for MySQL.
In Hibernate 6, an enum annotated @Enumerated(STRING) is mapped to:
a VARCHAR column type with a CHECK constraint on most databases, or
an ENUM column type on MySQL.
What I have found is to force the use of the String value, column definition needs to be added.
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = "provider", nullable = false, columnDefinition = "VARCHAR(255)") // columnDefinition = "VARCHAR(255)" is added
private ThirdPartyProviders provider;
Then the tests will pass.
JHipster Version(s)
8.1.0
JHipster configuration
Entity configuration(s) entityName.json
files generated in the .jhipster
directory
Browsers and Operating System
- Checking this box is mandatory (this is just to show you read everything)