3

给定表中的两个字段,我可以创建一个包含这两个字段的索引,如下所示:

@org.hibernate.annotations.Index(name = "IDX_REPORTID_RECNO")
private Integer reportId;

@org.hibernate.annotations.Index(name = "IDX_REPORTID_RECNO")
private Integer recNo;

我可以单独在每一列上创建索引

@org.hibernate.annotations.Index(name = "IDX_REPORTID")
private Integer reportId;

@org.hibernate.annotations.Index(name = "IDX_RECNO")
private Integer recNo;

但是它不允许我两者都做,这似乎是不允许的

@org.hibernate.annotations.Index(name = "IDX_REPORTID_RECNO")
@org.hibernate.annotations.Index(name = "IDX_REPORTID")
private Integer reportId;

@org.hibernate.annotations.Index(name = "IDX_REPORTID_RECNO")
@org.hibernate.annotations.Index(name = "IDX_RECNO")
private Integer recNo;

我怎样才能做到这一点 ?

4

1 回答 1

2

我认为您可以在类级别指定第二个索引:

@org.hibernate.annotations.Table(indexes = 
    @org.hibernate.annotations.Index(name = "IDX_REPORTID_RECNO",
        columnNames = {"reportId", "recNo"})
)
public class MyEntity {
    @org.hibernate.annotations.Index(name = "IDX_REPORTID")
    private Integer reportId;

    @org.hibernate.annotations.Index(name = "IDX_RECNO")
    private Integer recNo;
}
于 2013-01-18T09:08:51.227 回答