I'am trying to test JPA's @Index annotation which is avaliable since 2.1. But I can't find the documention how to use it.
When I'am trying:
@Index(columnList = "firstName")
private String firstName;
.. then Eclipse says: "The annotation @Index is disallowed for this location"
Does anyone know how to use it? Or has found the documentation for it? :-)
Thanks for any suggestions!
JPA allows us to achieve that by defining indexes from our code using @Index. This annotation is interpreted by the schema generation process, creating artifacts automatically. Note that it's not necessary to specify any index for our entities.
The @Entity annotation specifies that the class is an entity and is mapped to a database table. The @Table annotation specifies the name of the database table to be used for mapping.
We can use the @Basic annotation to mark a basic type property: @Entity public class Course { @Basic @Id private int id; @Basic private String name; ... } In other words, the @Basic annotation on a field or a property signifies that it's a basic type and Hibernate should use the standard mapping for its persistence.
The EntityManager API is used to create and remove persistent entity instances, to find entities by their primary key, and to query over entities. The set of entities that can be managed by a given EntityManager instance is defined by a persistence unit.
I've used the hibernate @Index
annotation just as you have with no issues, but it appears that the JPA @Index
annotation is stricter on where it can be used. Taken from a previous question - The annotation @Index is disallowed for this location :
The JPA Index annotation can only be used as part of another annotation like
@Table
,@SecondaryTable
, etc.
@Table(indexes = { @Index(...) })
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