Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define column type for enum

Tags:

hibernate

Upon upgrading from 6.1.7 to 6.2.0, I get this error message during schema validation:

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [receiving_status] in table [buddies_anonymized]; found [int (Types#INTEGER)], but expecting [tinyint (Types#TINYINT)]

The full class BuddyAnonymized can be found here. The attribute receivingStatus is declared as follows (no annotations applied):

private Status receivingStatus = Status.NOT_REQUESTED;

The type Status is an enum, defined as follows:

public enum Status
{
    NOT_REQUESTED, REQUESTED, ACCEPTED, REJECTED
}

This issue I reported on the Hibernate project as HHH-16422. As I didn't get a response yet, I wanted to implement a workaround and explicitly define the column type, like this:

    @Column(columnDefinition = "INTEGER")
    private Status receivingStatus = Status.NOT_REQUESTED;

However, the same error is still being reported. What is going wrong here?

like image 337
Bert Avatar asked Dec 05 '25 18:12

Bert


1 Answers

I got a response from the Hibernate team: This is a documented breaking change in Hibernate 6.2, see the 6.2 migration guide.

The solution is to add the @JdbcType annotation, as follows:

@JdbcType(value = SmallIntJdbcType.class)
private Status receivingStatus = Status.NOT_REQUESTED;
like image 117
Bert Avatar answered Dec 10 '25 21:12

Bert