Hi,
I need some assistance on this (seemingly) simple mapping:
Tables:
Code:
security
- securityId
- ... more columns
Code:
company_security
- companyId
- securityId
- rank
CompanySecurity.hbm.xml:
Code:
<composite-id>
<key-many-to-one name="company" column="companyId" class="Company"/>
<key-many-to-one name="security" column="securityId" class="Security"/>
</composite-id>
<property name="rank" column="rank"/>
Security.hbm.xml:
Code:
<id name="securityId" column="securityId">
<generator class="increment"/>
</id>
<join table="company_security" inverse="true">
<key column="security_id"/>
<many-to-one name="companySecurity" column="companyId" class="CompanySecurity"/>
</join>
The structure calls for many securities associated with a single company, but only one company associated with a particular security. I can get the one-to-many mapping fine for Company -> CompanySecurity but the Security -> CompanySecurity mapping gives me this exception:
Code:
org.hibernate.MappingException: Foreign key (FK4F9028C25CCF0F1B:company_security [companySecurity])) must have same number of columns as the referenced primary key (company_security [companyId,securityId])
We're working with a legacy database so I can't change structure. Could someone give a beginner some pointers?