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....

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Your first link redirects to 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?
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.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.