Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 485
dajohnson89 Avatar asked Nov 14 '13 16:11

dajohnson89


1 Answers

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

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

like image 64
Сергей Грачев Avatar answered Oct 15 '22 05:10

Сергей Грачев