Hi all
I need help setting oneToMany bidirectional relationship.
My entities are CUSTOMER and ORDER, each customer have several orders,
From each order I would like to be able to get the customer.
I get this exception on build:
AnnotationException: mappedBy reference an unknown target entity property: com.company.model.OrderEntity.customerEntity in com.company.model.CustomerEntity.OrderEntity
Please advise
Sharon
Customer Entity:
Code:
@Entity
@Table(name = "CustomerEntity")
public class CustomerEntity{
private Long customerId;
String name;
String code;
//List of children (OrderEntity)
private List<OrderEntity> orderEntityList;
//I removed all other getters / setters
@OneToMany(mappedBy="customerEntity",targetEntity=OrderEntity.class,fetch=FetchType.LAZY,cascade=CascadeType.MERGE)
@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
public List<OrderEntity> getOrderEntity() {
return orderEntityList;
}
public void setOrderEntity(List<OrderEntity> orderEntityList){
this.orderEntityList =orderEntityList ;
}
}
Order Entity:
Code:
@Entity
@Table(name = "OrderEntity")
public class OrderEntity {
private Long orderId;
private List<Products> prodCodes;
// Parent
private CustomerEntity customerEntity;
//I removed all other getters / setters
@ManyToOne
@JoinColumn(name="customerId", nullable=false)
public CustomerEntity getCustomerEntity () {
return customerEntity;
}
public void setCustomerEntity(CustomerEntity customerEntity) {
this.customerEntity = customerEntity;
}
}
Hibernate Tool Error:
[hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?
[hibernatetool] java.lang.reflect.InvocationTargetException
[hibernatetool] javax.persistence.PersistenceException: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.company.model.OrderEntity.customerEntity in com.company.model.CustomerEntity.OrderEntity
[hibernatetool] org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.company.model.OrderEntity.customerEntity in com.company.model.CustomerEntity.OrderEntity
Code: