6
@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.

2
  • 1
    Have you tried using a Hibernate Column Index? This grokbase post seems to indicate that creating a separate column index may be a viable solution: grokbase.com/p/postgresql/pgsql-performance/088mdgp5ar/… Commented Nov 14, 2013 at 17:02
  • As that discussion points out, there is no such thing as a Hibernate Column Index. Instead, one uses Hibernate to create an index over a particular column in the table. Commented Nov 14, 2013 at 17:53

1 Answer 1

2

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.