I'm creating a multi-column index as follows:
@Entity
public class Ranking extends Model {
@ManyToOne
@Index(name = "ranking_ix")
public Rankable rankable;
@ManyToOne
@Index(name = "ranking_ix")
public Criteria criteria;
@Index(name = "ranking_ix")
public double rank;
}
However I can't see how to control the order with which the three columns appear within the composite index (which can be required to ensure optimal query performance). How can this be achieved?
This can be specified with the org.hibernate.annotations.Table annotation, which is used in addition to the javax.persistence.Table annotation:
@Entity
@javax.persistence.Table(name="Ranking")
@org.hibernate.annotations.Table(
appliesTo="Ranking",
indexes = { @Index(name="ranking_ix", columnNames = { "rankable", "criteria", "rank" } ) }
)
public class Ranking extends Model {
@ManyToOne
public Rankable rankable;
@ManyToOne
public Criteria criteria;
@Index(name = "ranking_ix")
public double rank;
}
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