Morning.
I need to add indexing in hibernate entity. As I know it is possible to do using @Index annotation to specify index for separate column but I need an index
Please try the following:
@Entity
@org.hibernate.annotations.Table(appliesTo = House.TABLE_NAME,
indexes = {
@Index(name = "IDX_XDN_DFN",
columnNames = {House.XDN, House.DFN}
)
}
)
@Table(name="house")
public class House {
...
}
Note that this should also allow you to create a multi-column index (based on the index name):
@Index(name = "index1")
public String getFoo();
@Index(name = "index1")
public String getBar();
P.S.: What version of Hibernate are you using BTW? What database/dialect?
You have to have hibernate.hbm2ddl.auto set to create in persistence.xml. When set to update hibernate won't create indexes.
hibernate.hbm2ddl.auto = create
You'd better go with a composite primary key.
This article explains how to do it with JPA annotations. It uses @Embeddable
and @EmbeddedId