Possible Duplicate:
Specifying an index (non unique key) using JPA
Is there a way to define index on enitity column, to improve searches performance? I saw that hibernate gives @Index and @IndexColumn, but I am looking for JPA way to do it.
thanks
Here is an example of my entity, I need to index a name column
@Entity
@Table(name = "MY_TABLE")
public class MyEntity {
private long id;
private String name;
private String sourceInfo;
...
No, jpa doesn't provide any feature to define or create indexes. For some (unknown to me) reason, it's only possible to create unique indexes in JPA.
If you are not using hibernate or if you really don't want to use those annotations, you'll need to build your annotations and processor to output or update the database accordingly, but I don't think it's very trivial (and it's definitely, non standard)
Here's an example of how to define an index with Hibernate
@org.hibernate.annotations.Table(
appliesTo = "table_name",
indexes = {
@Index(name="single_column_index", columnNames = "col"),
@Index(name="multi_column_index", columnNames = {"col1", "col2"}),
}
)
OpenJPA allows you to specify non-standard annotation to define index on property.
Details are here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With