Reputation: 63
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?
Upvotes: 2
Views: 2649
Reputation: 692231
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.
Upvotes: 4