Hibernate OneToMany 关系错误

发布于 2024-11-18 12:08:00 字数 1576 浏览 1 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高冷爸爸 2024-11-25 12:08:00

您的类路径中可能有两个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文