Hibernate OneToMany 关系错误
我是 Hibernate 的新手。当我尝试在两个类之间建立一对多关系时,我失败了。
它给出了一个错误:
Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1912)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:1002)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:130)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:92)
at org.hibernate.business.TestBusiness.main(TestBusiness.java:14)
我的定义:
BusinessCard.java
@OneToMany(targetEntity=BusinessPhone.class, mappedBy="card",
cascade=CascadeType.ALL, fetch=FetchType.EAGER)
public List<BusinessPhone> getPhones() {
return phones;
}
BusinessPhone.java
@ManyToOne
@JoinColumn(name="business_id")
public BusinessCard getCard() {
return card;
}
public void setCard(BusinessCard card) {
this.card = card;
}
请帮助我错误的根源是什么?
I'm newbie on Hibernate. I failed when I try to make one to many relationship between two classes.
It gave an error:
Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1912)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:1002)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:130)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:92)
at org.hibernate.business.TestBusiness.main(TestBusiness.java:14)
My definitions:
BusinessCard.java
@OneToMany(targetEntity=BusinessPhone.class, mappedBy="card",
cascade=CascadeType.ALL, fetch=FetchType.EAGER)
public List<BusinessPhone> getPhones() {
return phones;
}
BusinessPhone.java
@ManyToOne
@JoinColumn(name="business_id")
public BusinessCard getCard() {
return card;
}
public void setCard(BusinessCard card) {
this.card = card;
}
Please help me what is the source of error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的类路径中可能有两个 jar 定义相同的 OneToMany 注释,但版本不同(一个具有
orphanRemoval
属性,另一个没有该属性)。修复你的类路径。You probably have two jars in your classpath defining the same OneToMany annotation, but in different versions (one having the
orphanRemoval
attribute and the other one not having it). Fix your classpath.