Hibernate OneToMany关系错误

时间:2011-07-04 11:10:05

标签: java database hibernate one-to-many

我是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;
}

请帮我解决错误来源是什么?

1 个答案:

答案 0 :(得分:4)

您的类路径中可能有两个jar定义相同的OneToMany注释,但是在不同的版本中(一个具有orphanRemoval属性而另一个没有它)。修复你的类路径。