@Entity
public class FruitStore {
@Id
private Long storeId;
@ElementCollection
private Set<Fruit> fruits;
}
当然,Fruit
类被标记为@Embeddable
。
在数据库中(准确地说是 postgresql,尽管这无关紧要),创建了一个名为 fruitstore_fruits
的表。它变得很大,对它的查询变得非常非常慢。我手动修改了数据库,使 fruitstore_fruits
表在 FruitStore
id
列上建立索引。令人高兴的是,这极大地提高了性能。我希望它自动完成。
问题是,我如何注释我的代码以使 Hibernate 自动索引 FruitStore
id
列上的 fruitstore_fruits?
编辑: This Hibernate bug已经消除了很多希望。我认为现在根本不支持我想要的。这有点令人难过,因为该功能并不是那么奇特(使用外部列索引元素集合)。然而,我喜欢在这里被证明是错误的。
最佳答案
看看它是如何完成的例子:
@CollectionTable(indexes = {@Index(columnList = "solution_version_training_session_id")})
关于java - Hibernate:为 ElementCollection 表创建索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19982772/