Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with Hibernates hbm2ddl.auto=validate and MySQL text types

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

like image 266
Ben Avatar asked May 10 '11 15:05

Ben


1 Answers

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

@Column(name = "DESCRIPTION", nullable = false, length = 65535, columnDefinition="TEXT")
like image 55
Xorty Avatar answered Oct 28 '22 12:10

Xorty