Paul Taylor
Paul Taylor

Reputation: 13120

Do you need to create index on the @id column of a Hibernate table

Do I need to add an index anoatation for the primary key of a hibernate table for decent performance, I assumed that marking a field with @id would mean an index was created

@Id
private String guid;

but I didnt notice anything being created in the ddl that was generated

But if I added an @index annotation

@Id
@org.hibernate.annotations.Index(name = "IDX_GUID")
private String guid;

then I do notice an index being created in the DDL.

So I'm thinking I need to do this for every table, but part of me is thinking is this really neccessary as surely hibernate would want indexes created for the primary key as a starting point ?

Upvotes: 5

Views: 2393

Answers (1)

Deepak Singhal
Deepak Singhal

Reputation: 10876

You do NOT have to create index explicitly. Instead of seeing DDL statements; I will recommend you to check the final schema created by hibernate. The index is created as part of create table statement.

Upvotes: 6

Related Questions