Wednesday, January 18, 2012

Hibernate: BLOB/TEXT column 'field_id' used in key specification without a key length

Working with Hibernate and JPA I've had a problem generating a schema. The generation would fail with following message:

org.hibernate.tool.hbm2ddl.SchemaUpdate - main   - BLOB/TEXT column 'field_id' 
used in key specification without a key length

The JPA mapping causing the problem looked like following:
 
@Column(name = prefix + "field_id", length = 256, unique=true, nullable=false)
private String fieldId;

Apparently, using hibernate in combination with MySQL causes this failure. The key element on the mapping is the length attribute. I've had to change it to length=255 and everything worked again.
@Column(name = prefix + "field_id", length = 255, unique=true, nullable=false)
private String fieldId;

Give it a try!

No comments:

Post a Comment