-->
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.  [ 1 post ] 
Author Message
 Post subject: problem mapping legacy tables
PostPosted: Sat Apr 04, 2009 3:40 pm 
Beginner
Beginner

Joined: Sat Jul 08, 2006 2:58 pm
Posts: 26
I am trying to use two legacy tables that are structured like this:

Code:
CREATE TABLE `ndc_main_multum_drug_code` (
  `main_multum_drug_code` int(11) default NULL,
  `principal_route_code` int(11) default NULL,
  `dose_form_code` int(11) default NULL,
  `product_strength_code` int(11) default NULL,
  `drug_id` varchar(6) default NULL,
  `csa_schedule` varchar(1) default NULL,
  `j_code` varchar(10) default NULL,
  `j_code_description` varchar(50) default NULL
)


CREATE TABLE `ndc_active_ingredient_list` (
  `main_multum_drug_code` int(11) default NULL,
  `active_ingredient_code` int(11) default NULL,
  `ingredient_strength_code` int(11) default NULL,
  `index` int(11) default NULL
)



where both tables share the same column, main_multum_drug_code` as the primary key.

I would like to map table `ndc_active_ingredient_list` as a list in table `ndc_main_multum_drug_code`

My class file for the ndc_main_multum_drug_code` table looks like this:

Code:
public class NdcMainMultumDrugCode  implements java.io.Serializable {


   private Integer id;
   ...
   private List<NdcActiveIngredientList> activeIngredients = new ArrayList<NdcActiveIngredientList>();
   ...

}


And my mapping file looks like this:

Code:
<class
    name="com.chisq.multum.bo.NdcMainMultumDrugCode"
    table="ndc_main_multum_drug_code"
>
    <id name="id"
        column="main_multum_drug_code"
        type="java.lang.Integer"
        length="11"
    >       
        <generator class="assigned" />
    </id>
           
   ...
   
     <list  name="activeIngredients"
           table="ndc_active_ingredient_list"
            lazy="true"
            cascade="all" >
           
            <key column="main_multum_drug_code" />
            <index column="index" />
            <one-to-many class="com.chisq.multum.bo.NdcActiveIngredientList" />
     </list>
   

    ...

    <!-- Associations -->
    <!-- derived association(s) for compound key -->
    <!-- end of derived association(s) -->
 

</class>


My class file for the ndc_active_ingredient_list table looks like this:

Code:
public class NdcActiveIngredientList  implements java.io.Serializable {



   private Integer id;
   private NdcActiveIngredient activeIngredient;
   private NdcIngredientStrength ingredientStrength;

   ...

}


and my mapping file looks like this:

Code:
<class
    name="com.chisq.multum.bo.NdcActiveIngredientList"
    table="ndc_active_ingredient_list"
>
    <id name="id"
        column="main_multum_drug_code"
        type="java.lang.Integer"
        length="11"
    >       
        <generator class="assigned" />
    </id>
   
    <many-to-one
            name="activeIngredient"
            class="com.chisq.multum.bo.NdcActiveIngredient"
            cascade="all"
            outer-join="auto"
            update="false"
            insert="false"
            column="active_ingredient_code"
            not-null="false"
        />
    <many-to-one
            name="ingredientStrength"
            class="com.chisq.multum.bo.NdcIngredientStrength"
            cascade="all"
            outer-join="auto"
            update="false"
            insert="false"
            column="ingredient_strength_code"
            not-null="false"
        />     
   
    <!-- Associations -->
    <!-- derived association(s) for compound key -->
    <!-- end of derived association(s) -->
 
</class>




Everything is working fine, I can get a record from the ndc_main_multum_drug_code table except that the list of activeIngredients is incorrect. It contains the correct number in the list but the items in the list are all the same, here's what my tostring method prints out:


Code:
[junit] record = [NdcMainMultumDrugCode: id: 37
    [junit]  principalRoute: [MultumRoute: routeCode: 2426 routeAbbr: PO routeDescription: oral]
    [junit]  doseForm: [MultumDoseForm: doseFormCode: 2440 doseFormAbbr: CAP doseFormDescription: capsule]
    [junit]  productStrength: [MultumProductStrength: productStrengthCode: 7253 productStrengthDescription: 325 mg-50 mg]
    [junit]  drug: [MultumDrug: drugId: d03456 drugName: acetaminophen-butalbital]

    [junit]  activeIngredients:
[[NdcActiveIngredientList: id: 37 activeIngredient: [NdcActiveIngredient: activeIngredientCode: 4119 activeIngredient: acetaminophen] ingredientStrength: [NdcIngredientStrength: ingredientStrengthCode: 6538 strengthNumAmount: 325.0 strengthNumUnit: 678 strengthDenomAmount: 1.0 strengthDenomUnit: 684]],

[NdcActiveIngredientList: id: 37 activeIngredient: [NdcActiveIngredient: activeIngredientCode: 4119 activeIngredient: acetaminophen] ingredientStrength: [NdcIngredientStrength: ingredientStrengthCode: 6538 strengthNumAmount: 325.0 strengthNumUnit: 678 strengthDenomAmount: 1.0 strengthDenomUnit: 684]]]
    [junit]  csaSchedule: 0
    [junit]  JCode:
    [junit]  JCodeDescription: null]
    [junit] ------------- ---------------- ---------------




Can anyone see what I'm doing wrong? Am I mapping the list incorrectly?


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

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.