-->
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.  [ 7 posts ] 
Author Message
 Post subject: composite-id's and generator
PostPosted: Thu Nov 13, 2003 12:52 pm 
Newbie

Joined: Mon Nov 10, 2003 2:48 am
Posts: 8
Location: GE Medical Systems
Hello,

I have not been able to figure out how to use generator on tables with composite id's.

How can I place a generator for column Admission_ID on the below table?
Is there a better way to layout the hbm file?

Code:
Table: T_CX1_AdmDis                        
PK = 3   Column Name   Column Type   Size   Precision   Notes         
3      Admission_ID      int            4          10   Auto generated Column and Part of comp-id         
3      PatID             int            4          10   Part of comp-id         
3      Participant_ID    varchar       50           0   Part of comp-id         
1      AdmitDt           datetime       8           0   Normal Column         
1      DischDt           datetime       8           0   Normal Column         


here is the hbm mapping:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class name="com.ge.med.registries.cx1.TCx1ParticipantM" table="T_CX1_Participant_M">
      <id column="Participant_ID" name="id" type="java.lang.Long">
         <generator class="assigned"/>
      </id>
      <property column="ParticipantName" length="100" name="participantname" type="java.lang.String"/>
      <property column="ZipPassword" length="50" name="zippassword" type="java.lang.String"/>
      <property column="RegistryType" length="50" name="registrytype" type="java.lang.String"/>
      <property column="Site_ID" length="10" name="siteId" type="java.lang.Integer"/>
      <set name="PtSites" lazy="true" cascade="all" table="T_CX1_PtSite_T">
         <key column="Participant_ID"/>
         <one-to-many class="com.ge.med.registries.cx1.TCx1PtsiteT"/>
      </set>
   </class>
   <class name="com.ge.med.registries.cx1.TCx1PatientT" table="T_CX1_Patient_T">
      <id column="PatID" name="id" type="java.lang.Long">
         <generator class="native"/>
      </id>
      <property column="PatFName" length="50" name="patfname" type="java.lang.String"/>
      <property column="PatMInit" length="1" name="patminit" type="java.lang.String"/>
      <property column="PatLName" length="50" name="patlname" type="java.lang.String"/>
      <property column="SSN" length="50" name="ssn" type="java.lang.String"/>
      <property column="Gender" length="3" name="gender" type="java.lang.String"/>
      <property column="DOB" length="23" name="dob" type="java.util.Date"/>
      <property column="PhoneNumber" length="50" name="phonenumber" type="java.lang.String"/>
      <property column="Address" length="100" name="address" type="java.lang.String"/>
      <property column="City" length="50" name="city" type="java.lang.String"/>
      <property column="State" length="50" name="state" type="java.lang.String"/>
      <property column="Zip" length="50" name="zip" type="java.lang.String"/>
      <set name="PtSites" lazy="true" cascade="all" table="T_CX1_PtSite_T" inverse="true">
         <key column="PatID"/>
         <one-to-many class="com.ge.med.registries.cx1.TCx1PtsiteT"/>
      </set>
   </class>
   <class name="com.ge.med.registries.cx1.TCx1PtsiteT" table="T_CX1_PtSite_T">
      <composite-id unsaved-value="any">
         <key-many-to-one name="Participant" class="com.ge.med.registries.cx1.TCx1ParticipantM" column="Participant_ID"/>
         <key-many-to-one name="Patient" class="com.ge.med.registries.cx1.TCx1PatientT" column="PatID"/>
      </composite-id>
   </class>
   <class name="com.gems.test.cx.TCx1AdmdisT" table="T_CX1_AdmDis_T">
      <composite-id>
         <key-many-to-one name="namePatientSite" class="com.ge.med.registries.cx1.TCx1PtsiteT">
            <column name="Participant_ID" not-null="true"/>
            <column name="PatID" not-null="true"/>
         </key-many-to-one>
         <key-property column="Admission_ID" length="10" name="admissionId" type="java.lang.Integer">
            <generator class="native"/>
         </key-property>
      </composite-id>
      <property column="AdmitDt" length="23" name="admitdt" type="java.util.Date"/>
      <property column="DischDt" length="23" name="dischdt" type="java.util.Date"/>
   </class>
   <class name="com.ge.med.registries.a31.TA3PatientT" table="a3.T_A3_Patient_T">
      <composite-id unsaved-value="any">
         <key-many-to-one name="PatientSite" class="com.ge.med.registries.cx1.TCx1PtsiteT">
            <column name="Participant_ID" not-null="true"/>
            <column name="PatID" not-null="true"/>
         </key-many-to-one>
      </composite-id>
      <property column="Race" length="5" name="race" type="java.lang.Short"/>
   </class>
</hibernate-mapping>

Thanks in advance for any help on this issue.
-Al


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 12:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It does not make sense to have a generated value as part of a composite key. If it is generated, it is, or can be, unique by itself.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 1:01 pm 
Newbie

Joined: Mon Nov 10, 2003 2:48 am
Posts: 8
Location: GE Medical Systems
So this means that you can have id and composite-id on the same table?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 1:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It probably means that you don't need to map the composite-id at all, I suppose.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 1:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Or perhaps you use the composite-id in some foreign keys? Uggghhhh if thats the case, your relational model is quite redundant.

Identity columns are unique by themselves. They don't need any other columns in the PK.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 1:12 pm 
Newbie

Joined: Mon Nov 10, 2003 2:48 am
Posts: 8
Location: GE Medical Systems
Ok, that makes sense. I will use an id element to autogen the admission_id for the table and place the other two columns as properties only.

Thanks, for the help.
-Al


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 1:17 pm 
Newbie

Joined: Mon Nov 10, 2003 2:48 am
Posts: 8
Location: GE Medical Systems
Yes, the relational model is very redundant. And the other two columns are used in foreign keys.

Should I have the DB structure changed to remove the other columns for the PK?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.