3

Given two fields in a table I can create an index that encompases both as follows:

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

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

and I can create indexes on each column individually

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

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

But it doesnt let me do both, this doesn't seem to be allowed

@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;

How can I do this ?

1 Answer 1

2

I think you can specify the second index at class level:

@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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I'm getting The type Index is deprecated. Any alternatives?

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.