dajohnson89
dajohnson89

Reputation: 79

Hibernate: Creating an index for an ElementCollection table

@Entity
public class FruitStore {

@Id
private Long storeId;

@ElementCollection
private Set<Fruit> fruits;

}

Of course, the Fruit class is marked @Embeddable.

In the database (postgresql to be exact, although it shouldn't matter), there is a table created called fruitstore_fruits. It grows huge, and queries on it become very very slow. I have manually modified the database, such that the fruitstore_fruits table indexes on the FruitStore id column. Happily, this dramatically improves performance. I want this to be done automatically.

The question is, how can I annotate my code to get Hibernate to automatically index the fruitstore_fruits on the FruitStore id column?

EDIT: This Hibernate bug has removed lots of hope. I think what I want is simply not supported right now. Which is kinda sad, because the feature isn't that exotic (indexing a element collection with a foreign column). However, I'd love to be proven wrong here.

Upvotes: 6

Views: 3638

Answers (1)

Take a look for example of how it could be done:

@CollectionTable(indexes = {@Index(columnList = "solution_version_training_session_id")})

Upvotes: 2

Related Questions