6

I've tried to enable hbm2ddl.auto=validate on a project I've inherited. I now get a lot of wrong column type exceptions for String properties which are mapped either with text or mediumtext (MySQL database).

The mapping is:

@Column(name = "DESCRIPTION", nullable = false, length = 65535)
@Length(max = 65535)
@NotNull
public String getDescription() {
    return this.description;
} 

And the datatype in the db is 'text' (utf8_general_ci).

I thought this should be the right mapping but Hibernate is complaining that it found text but was expecting longtext.

I've checked the hibernate configuration and there wasn't a dialog specified. I've added

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>

but that doesn't seem to make a difference.

I know I can add columnDefinition="text" to the mapping but I would have to do that in a lot of places and IMHO the mapping should be correct already. So what is going wrong? Any ideas?

Thanks

Xorty
  • 18,367
  • 27
  • 104
  • 155
Ben
  • 1,922
  • 3
  • 23
  • 37

1 Answers1

12

You have to add columnDefinition to @Column annotation, like this:

@Column(name = "DESCRIPTION", nullable = false, length = 65535, columnDefinition="TEXT")
Xorty
  • 18,367
  • 27
  • 104
  • 155