简体   繁体   English

Hibernate OneToMany 关系错误

[英]Hibernate OneToMany Relation Error

I'm newbie on Hibernate.我是 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名片.java

@OneToMany(targetEntity=BusinessPhone.class, mappedBy="card",
        cascade=CascadeType.ALL, fetch=FetchType.EAGER)
public List<BusinessPhone> getPhones() {
    return phones;
}

BusinessPhone.java商务电话.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?请帮助我错误的根源是什么?

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).您的类路径中可能有两个 jars 定义相同的 OneToMany 注释,但版本不同(一个具有orphanRemoval属性,另一个没有它)。 Fix your classpath.修复你的类路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM