-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: need help with <key-many-to-one>
PostPosted: Tue Aug 21, 2007 1:29 pm 
Newbie

Joined: Fri Dec 09, 2005 12:34 pm
Posts: 6
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...

_________________
-------------------------------------------------------
"The effort of using machines to mimic the human mind has always struck me as rather silly. I would rather use them to mimic something better." - Edsger Dijkstra


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 2:38 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
You should probably use simple surrogate primary keys instead of composites - it would make your life a lot simpler.

However, if I've understood correctly you want to fetch instances of BenefitComponentDetailHolder using a where clause that refers to properties from the BenefitComponentHolder. Right?

This can be done as follows (hql):
Code:
from BenefitComponentDetailHolder where id.benefitComponent.statusCode='open'


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 3:04 pm 
Newbie

Joined: Fri Dec 09, 2005 12:34 pm
Posts: 6
I wish I could use a simple primary key, but I'm (unfortunately) not in charge of the database development at work. Believe me, we fought long and hard to try and do that... :-)

_________________
-------------------------------------------------------
"The effort of using machines to mimic the human mind has always struck me as rather silly. I would rather use them to mimic something better." - Edsger Dijkstra


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.