Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All TopicsHi,
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_CO
org.hibernate.MappingExcep
at org.hibernate.mapping.Fore
at org.hibernate.mapping.Fore
at org.hibernate.cfg.Configur
at org.hibernate.cfg.Configur
at org.hibernate.cfg.Configur
at FirstExample.main(FirstExa
This is the mapping used:
// Agency.hbm.xml
<hibernate-mapping>
<class name="test.bean.Agency" schema="ECITATION" table="AGENCY">
<composite-id name="agencyPK" class="test.bean.AgencyPK"
<key-property column="AGENCY_CODE" length="4" name="agencyCode" type="java.lang.String"/>
<key-property column="SUB_AGENCY_CODE" length="4" name="subAgencyCode" type="java.lang.String"/>
</composite-id>
<property column="AGENCY_NAME" length="50" name="agencyName" type="java.lang.String"/>
<property column="AGENCY_TYPE" length="50" name="agencyType" type="java.lang.String"/>
<set name="officerAgency" lazy="true" inverse="true">
<key column="INT_OFCR2AGCY_ID">
<one-to-many class="test.bean.OfficerAg
</set>
</class>
</hibernate-mapping>
--------------------------
// OfficerAgency.hbm.xml
<hibernate-mapping>
<class name="test.bean.OfficerAge
<id column="INT_OFCR2AGCY_ID" name="intOfcr2agcyId" type="java.lang.Long">
<generator class="sequence"/>
</id>
<property column="AGENCY_CODE" length="4" name="agencyCode" not-null="true" type="java.lang.String"/>
<property column="SUB_AGENCY_CODE" length="4" name="subAgencyCode" not-null="true" type="java.lang.String"/>
<property column="START_DATE" length="7" name="startDate" type="java.util.Date"/>
<property column="END_DATE" length="7" name="endDate" type="java.util.Date"/>
<many-to-one name="agencyPK" class="us.md.state.courts.
</many-to-one>
</class>
</hibernate-mapping>
--------------------------
How can define the relationship in Hibernate? Could someone please help?
Thanks in advance,
Jenny
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: assystPosted on 2007-02-16 at 03:37:01ID: 18547529
Comments are available to members only. Sign up or Log in to view these comments.