gpt4 book ai didi

java - Hibernate OneToMany 关系错误

转载 作者:搜寻专家 更新时间:2023-10-30 20:12:26 26 4
gpt4 key购买 nike

我是 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com