Question

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 ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top