Hello,
I'm having a big problem with my Hibernate Mapping files when I try to map a bi-directional relationship (one-to-many) where the parent's composite key is part of the child's composite key.
Here's the mapping for the parent:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/HibernateMapping DTD3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="BenefitComponentHolder" table="BNFT_COMP">
<meta attribute="implement-equals">true</meta>
<composite-id>
<key-property name="identifier" column="BNFT_COMP_ID" type="int" />
<key-property name="effectiveFromDate" column="BC_EFF_FROM_DATE" type="date" />
</composite-id>
<property name="statusCode" column="STS_CODE" type="string" />
<property name="componentTypeCode" column="COMP_TYPE_CODE" type="string" />
<property name="templateTypeCode" column="TMPLT_TYPE_CODE" type="string" />
<property name="benefitRiderTypeCode" column="BNFT_RDR_TYPE_CODE" type="string" />
<property name="effectiveThroughDate" column="BC_EFF_THRU_DATE" type="date" />
<property name="componentSubTypeCode" column="COMP_SBTP_CODE" type="string" />
<property name="componentTemplateIdentifier" column="COMP_TMPLT_ID" type="int" />
<property name="componentTemplateEffectiveFromDate" column="COMP_TMPLT_EFF_DT" type="date" />
<property name="name" column="NAME_DSCRPTR" type="string" />
<property name="description" column="DESC" type="string" />
<set name="benefitComponentDetails" inverse="true" fetch="join" batch-size="1000" lazy="false" cascade="all" >
<key>
<column name="BNFT_COMP_ID" not-null="true"/>
<column name="BC_EFF_FROM_DATE" not-null="true"/>
</key>
<one-to-many class="com.excellus.service.product.holder.BenefitComponentDetailHolder"/>
</set>
</class>
</hibernate-mapping>
And here's the mapping for the child:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/HibernateMapping DTD3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="BenefitComponentDetailHolder" table="BNFT_COMP_DTL">
<meta attribute="implement-equals">true</meta>
<composite-id>
<key-many-to-one name="benefitComponent" class="BenefitComponentHolder">
<column name="BNFT_COMP_ID" not-null="true" />
<column name="BC_EFF_FROM_DATE" not-null="true" />
</key-many-to-one>
<key-property name="identifier" column="BNFT_DTL_SQNC_NBR" type="integer"/>
</composite-id>
<property name="benefitCategoryCode" column="BNFT_CAT_CODE" type="string" />
<property name="benefitDetailCode" column="BNFT_DTL_CODE" type="string" />
<property name="placeOfServiceCode" column="POS_CODE" type="string" />
<property name="benefitApplicabilityCode" column="BNFT_APLCBLTY_CD" type="string" />
<property name="benefitApplicabilityNumber" column="BNFT_APLCBLTY_NBR" type="string" />
<property name="benefitLevelCode" column="BNFT_LVL_CODE" type="string"/>
<property name="benefitCoverageTypeCode" column="BNFT_COV_TYPE_CODE" type="string" />
<property name="coverageTypeCode" column="COV_VRBL_TYPE_CODE" type="string" />
<property name="coverageVariableValue" column="COV_VRBL_VLU" type="string" />
<property name="benefitCopayTypeCode" column="BNFT_CPY_TYPE_CODE" type="string" />
<property name="copayTypeCode" column="CPY_VRBL_TYPE_CODE" type="string" />
<property name="copayVariableValue" column="CPY_VRBL_VLU" type="string" />
<property name="benefitCoinsuranceTypeCode" column="BNFT_COINS_TYPE_CD" type="string" />
<property name="coinsuranceTypeCode" column="COINS_VRBL_TYPE_CD" type="string" />
<property name="coinsuranceVariableValue" column="COINS_VRBL_VLU" type="string" />
<property name="benefitCoinsuranceMaxTypeCode" column="BNFT_COINS_MAX_TYP" type="string" />
<property name="coinsuranceMaxTypeCode" column="COINS_MAX_VRBL_TYP" type="string" />
<property name="coinsuranceMaxVariableValue" column="COINS_MAX_VRBL_VLU" type="string" />
<property name="familyCoinsuranceMaxAmount" column="FMLY_COINS_MAX_AMT" type="string" />
<property name="benefitDeductibleTypeCode" column="BNFT_DDCTBL_TYP_CD" type="string" />
<property name="deductibleTypeCode" column="DDCTBL_VRBL_TYP_CD" type="string" />
<property name="deductibleVariableValue" column="DDCTBL_VRBL_VLU" type="string" />
<property name="familyDeductibleAmount" column="FMLY_DDCTBL_AMT" type="string" />
<property name="description" column="DESC" type="string" />
<property name="footNote" column="FOOT_NOTE" type="string" />
<property name="lineOfBusinessCode" column="LOB_CODE" type="string" />
<property name="providerTypeCode" column="PROV_TYPE_CODE" type="string" />
<property name="memberAgeTierCode" column="MBR_AGE_TIER_CODE" type="string" />
<property name="drugTierCode" column="DRUG_TIER_CODE" type="string" />
<property name="visitTierCode" column="VISIT_TIER_CODE" type="string" />
<property name="minMemberAgeNumber" column="MIN_MBR_AGE_NBR" type="integer" />
<property name="maxMemberAgeNumber" column="MAX_MBR_AGE_NBR" type="integer" />
<property name="minVisitNumber" column="MIN_VISIT_NBR" type="integer" />
<property name="maxVisitNumber" column="MAX_VISIT_NBR" type="integer" />
<set name="benefitDetailLimits" inverse="true" fetch="join" lazy="false" batch-size="1000" cascade="all">
<key>
<column name="BNFT_COMP_ID" not-null="true"/>
<column name="BC_EFF_FROM_DATE" not-null="true"/>
<column name="BNFT_DTL_SQNC_NBR" not-null="true"/>
</key>
<one-to-many class="BenefitComponentDetailLimitHolder"/>
</set>
</class>
</hibernate-mapping>
Everything seems to work perfectly fine if I'm only dealing with the parent, but I need to do something that I just can't figure out how to so easily with the mapping like this: search the child table using the ID of the parent and other information. The main problem is that I can't reference the columns because they don't have fields in the Holder object (they're contained within the BenefitComponentHolder reference). If anyone knows a better way to map this relationship so that I can achieve this functionality and keep the functionality around the parent, let me know. I can't think of anything except writing out the SQL by hand...