JPA: defining an index column
indexing, jpa, jpa-2.0
Solution
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)
Edit
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"}),
}
)
Problem
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; ... ```