mysqlhibernatevalidationschemawildfly

Wildfly 32: Schema-Validation Error: Found Types#VARCHAR but expecting Types#ENUM


The problem occurs with WIldfly 32.

I build my Wildfly Environment in a bootable jar. After I updated Wildfly 28 to 32 with galleon and when I build and try to run it, Wildfly starts with errors. One Error that occurs is caused by the Hibernate

SchemaManagementException: wrong column type in column [my_column] in table [`my_entity`]; found [varchar (Types#VARCHAR)], but expecting [`varchar` (Types#ENUM)]

My Entity looks like this:


@Entity
@Table(name = "my_entity")
public class MyEntity {

  public enum MyEnum {
    [...]
  }
  [...]
  @NotNull
  @Enumerated(EnumType.STRING)
  @Column(name = "my_column", columnDefinition = "varchar")
  private MyEnum myColumn;
  [...]

whereas in my Mysql Database I defined the my_column as follows:

[...]
`my_column` VARCHAR(50) NOT NULL,
[...]

Searching for Solutions, people suggest to use the columnDefinition = "varchar" in the @Column annotation. I tried it but it didn't work for me. It just somehow affects the name but not the type: [`varchar` (Types#ENUM)] as stated before. I thought by changing the columnDefinition I change the expected type. But the expected type was still Types#ENUM.

Other Suggestions were to write an own specific Converter for this enum, which I really want to avoid because I have tons of Enums in my Project and I want to refrain from writing a Converter for each single Enum.

Do I miss something or is there any other solution?


Solution

  • One solution to declare the right expected type is to add a JdbcTypeCode Annotation with the expected type to the Enum variable:

    @JdbcTypeCode(Types.VARCHAR)
    

    so in this example it is:

    @NotNull
    @Enumerated(EnumType.STRING)
    @JdbcTypeCode(Types.VARCHAR)
    @Column(name = "my_column", columnDefinition = "varchar")
    private MyEnum myColumn;