I'm trying the Hibernate mapping between two tables - AGENCY and OFFICER_AGENCY.
The AGENCY table has the composite primary key which consists of agency_code and sub_agency_code. This is defined as a composite Java object AgencyPK.
The table AGENCY holds a one-to-many relationship with OFFICER_AGENCY, which has int_ofcr2agcy_id as the primary key and has foreign key reference to the agency_code and sub_agency_code fields of table AGENCY.
The following exception is thrown when I try to map the relationships:
Foreign key (FKBB3E234E2C0B82A3 OFFICER_AGENCY [INT_OFCR2AGCY_ID])) must have same number of columns as the referenced primary key (AGENCY [AGENCY_CODE,SUB_AGENCY_CODE]) org.hibernate.MappingException: Foreign key (FKBB3E234E2C0B82A3 O FFICER_AGENCY [INT_OFCR2AGCY_ID])) must have same number of columns as the referenced primary key (AGENCY [AGENCY_CODE,SUB_AGENCY_CODE]) at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90) at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73) at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1145) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1052) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1168) at FirstExample.main(FirstExample.java:23)