如何为子表定义索引

问题描述 投票:3回答:1

我遇到了一个情况。下面定义了一个父类和一个由父类派生的子类。由于父代有 @Table 注解,我可以定义索引。但由于没有 @Table 注解在子列中,我怎么能定义索引的子列。我想使用 @SecondaryTable 注释,但比我认为 @InheritanceType.SINGLE_TABLE 是无用的,因为将创建另一个子表。如果我错了,请纠正。另外,如果有任何解决方案的子索引问题。

@Table(name = "Parent", indexes = {@Index(name = "IDX_USERNAME", columnList = "username")})
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE")
@Entity
public class Parent{
}

@Entity
@DiscriminatorValue("C")
public class Child extends Parent{
}
java hibernate jpa indexing hibernate-mapping
1个回答
1
投票

唯一的方法是使用Hibernate特定的 @索引注释:

@org.hibernate.annotations.Index(name = "CHILD_NAME_IDX", columnNames = "name")
private String name;

该说明是 弃用但你可以将它应用于字段或方法。

© www.soinside.com 2019 - 2024. All rights reserved.