I have a data model where I need a String
column to be indexed by the backing database:
@Entity
public class A {
// ...
@Column(length=2048)
@Index(name="strFieldIndex")
private String strField;
}
When adding the length
attribute of @Column(length=2048)
(for which hibernate doesn't generate varchar anymore) the following error message appears on MySQL
:
ERROR org.hibernate.tool.hbm2ddl.SchemaExport -
BLOB/TEXT column 'strField' used in key specification without a key length
I've scanned the API docs for hibernate and I can't find an approach to setting the key length.
I think you have to declare this index manually as required for MySQL, since Hibernate can't handle all DBMS-specific requirements. For example, using <database-object>
syntax.