我是 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)
我的定义:
名片.java
@OneToMany(targetEntity=BusinessPhone.class, mappedBy="card",
cascade=CascadeType.ALL, fetch=FetchType.EAGER)
public List<BusinessPhone> getPhones() {
return phones;
}
商务电话.java
@ManyToOne
@JoinColumn(name="business_id")
public BusinessCard getCard() {
return card;
}
public void setCard(BusinessCard card) {
this.card = card;
}
请帮我看看错误的根源是什么?
最佳答案
您的类路径中可能有两个 jar 包定义了相同的 OneToMany 注释,但版本不同(一个具有 orphanRemoval
属性,另一个没有该属性)。修复你的类路径。
关于java - Hibernate OneToMany 关系错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6570674/