I have a schema (simplified) as follows, 2 entities with a one to many association between DEALER and BUSINESS_OFFICE (there can be many business offices under a single dealer):
DEALER ( DEALER_ID PK, NAME )
BUSINESS_OFFICE ( BUSINESS_OFFICE_ID PK, DEALER_ID FK to DEALER.DEALER_ID NAME )
and domain object fields annotated as follows:
Dealer class:
@Id @Column(name="DEALER_ID") private int dealerId; ..other attributes..
@OneToMany @JoinTable(name = "BUSINESS_OFFICE", joinColumns = {@JoinColumn(name="dealerId", referencedColumnName="DEALER_ID")}) private Set<BusinessOffice> businessOffices = new HashSet<BusinessOffice>(0);
Business office class:
@Id @Column(name="BUSINESS_OFFICE_ID") private int businessOfficeId; .. other attributes ..
The problem I am having is with the OneToMany mapping, I get this error message:
Caused by: org.hibernate.MappingException: Foreign key (FKD13E481B940D703:BUSINESS_OFFICE [businessOffices_BUSINESS_OFFICE_ID])) must have same number of columns as the referenced primary key (BUSINESS_OFFICE [internalDealerId,businessOffices_BUSINESS_OFFICE_ID])
I have no idea what in the world this means... there is only 1 primary key in BUSINESS_OFFICE both as annotated by @Id in the class and in the database table..why is it implying that there is a composite key in BUSINESS_OFFICE? In the BUSINESS_OFFICE table "internalDealerId" is not a PK but rather a FK to the DEALER table.
Any ideas what I am doing wrong? this is a simple association, nothing complex, not sure what I am missing.. thanks much!
|