Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

java - The annotation @Index is disallowed for this location

When trying to use the @Index annotation from javax.persistence, Eclipse gives me this error.

I'm using it right before a java.util.Date field, inside a class annotated with @Entity.

Before, I was using org.hibernate.annotations.Index in the exact same place and it was fine.

The problem started after I've upgraded hibernate-core from 4.1.9.Final to 4.3.0.Beta3 and hibernate-commons-annotations from 4.0.1 to 4.0.2. It says @Index is deprecated and recommends the javax.persistence one.

All docs and examples I've found put @Index before class members. What am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The JPA Index annotation can only be used as part of another annotation like @Table, @SecondaryTable, etc. (see the See Also section in the javadoc):

@Table(indexes = { @Index(...) })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...