Varchar(1) column for java enum fails with ClassCastException

When upgrading from Hibernate 5 to Hibernate 6, the following column/java type causes failures:

public enum Mode { A, S, R };

@Enumerated(EnumType.STRING)
@Column(length = 1)
@JdbcType(VarcharJdbcType.class)
Mode mode;

The column type in the DB is a varchar(1). In Hibernate 5, it considered this column a String and successfully converts to a Mode enum without any intervention. In Hibernate 6, it considers the column a java.lang.Character and thus cannot convert it to a Mode. I’ve tried using an AttributeConverter<Mode, String> but it doesn’t seem to work in all cases. Especially when the column is used in a composite key.

The only fix I’ve found is to change the db column to a varchar(4) and the @Column to a length =4. It’s not ideal but it works.

I’m currently using 6.2.2.Final

This is very similar to what was discussed in this post. A JIRA issue was opened for this [HHH-16498] - Hibernate JIRA, you can follow that for any updates.

Would you mind creating a reproducer for this and create a new JIRA issue please? The issue you are describing seems to be a different one than HHH-16498.

I’ll try to when I get time.