1

I'm use hibernate JPA

hibernate version is 3.5.1-Final and hibernate-annotations version is 3.5.1-Final too

and mysql version is : 5.5.35-0ubuntu0.12.04.2

I have a column:

@Column(name = "TITLE", length = 300)
@Index(name = "I_PRODUCT_ITEM_TITLE")
public String getTitle() {
    return title;
}

but create index, show me

ERROR o.h.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create index I_PRODUCT_ITEM_TITLE on T_PRODUCT_ITEM (TITLE)
ERROR o.h.tool.hbm2ddl.SchemaUpdate - BLOB/TEXT column 'TITLE' used in key specification without a key length

I don't know the reason....

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
feilong
  • 721
  • 1
  • 12
  • 25

2 Answers2

1

Because you specified a length of 300, the column type was set to TEXT by Hibernate.

Adding an index on a TEXT column requires you to specify a length prefix and as it seems Hibernate can't add that properly.

If you don't need a length 300 and you can live with 255 than you can go for that.

Otherwise you may choose to create the schema yourself with incremental update scripts, which is the preferred way for production systems.

You should create a Hibernate JIRA issue describing this issue. Some complained about it since 2005.

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
  • Your first link redirects to https://dev.mysql.com/doc/refman/8.0/en/char.html, stating that VARCHAR is limited to 64k (shared among all columns), so Hibernate should use VARCHAR(300), shouldn't it? – maaartinus Sep 12 '19 at 01:28
  • 1
    I updated the answer. This issue is for Hibernate 3.5, which is very old. Better try it with 5.x and see if the issue still replicates. – Vlad Mihalcea Sep 12 '19 at 03:45
0

Jpa doesn't provide any feature to define or create indexes.You can just create unique indexes with JPA.

You can create index with hibernate.

This answer can help you to create index with hibernate..

Jpa Defining An Index Column

Community
  • 1
  • 1
mstzn
  • 2,881
  • 3
  • 25
  • 37