开发者

Hibernate: What am I missing? Can't find @Id, instead @Index

Every example I have found uses @Id, but when I try to write my code, many of the annotations that I'm used to are gone, there are annotatoins like @Index, and the @Entity parameters have changed. I've looked through the Hibernate documentation, and can't find anything talking about changing all of their annotations, so am I looking at a bogus version?

开发者_如何学Go

Even @Column() with a name is gone, this is extremely confusing, I'm using Hibernate 3, but I find it hard to believe they went through and broke EVERY annotation that they used to support.

I downloaded the most recent version of Hibernate3.jar, that's all I've included, looking through the JAR I see the annotations packages

import org.hibernate.annotations.Entity;
import org.hibernate.annotations.Table;


I think a wrongly defined class path on your side is more likely than a bogus version. And without more details about the version of Hibernate you're using, the JARs you have on the class path, I don't know what to add.

Update: I'd suggest to use JPA annotations over Hibernate annotations. Here are the dependencies I'm using with the latest version of Hibernate Entity Manager:

org.hibernate:hibernate-entitymanager:jar:3.5.3-Final:compile
+- org.hibernate:hibernate-core:jar:3.5.3-Final:compile
|  +- antlr:antlr:jar:2.7.6:compile
|  +- commons-collections:commons-collections:jar:3.2:compile
|  +- dom4j:dom4j:jar:1.6.1:compile
|  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
|  \- javax.transaction:jta:jar:1.1:compile
+- org.hibernate:hibernate-annotations:jar:3.5.3-Final:compile
|  \- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
+- cglib:cglib:jar:2.2:compile
|  \- asm:asm:jar:3.1:compile
+- javassist:javassist:jar:3.9.0.GA:compile
\- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile


No, the annotations haven't changed.

It's hard to us for know if you are looking at a bogus version without knowing what is on your classpath.

Are you sure that hibernate-annotations is on your classpath? As well as the JAR containing the javax.persistence classes (such as hibernate-jpa-2.0-api-1.0.0.Final.jar)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜