[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-2198) Multiple Primary Keys Composite-id Mapping problem

Christian Bauer (JIRA) noreply at atlassian.com
Tue Oct 31 00:17:05 EST 2006


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2198?page=all ]
     
Christian Bauer resolved HHH-2198:
----------------------------------

    Resolution: Rejected

http://forum.hibernate.org

> Multiple Primary Keys Composite-id Mapping problem
> --------------------------------------------------
>
>          Key: HHH-2198
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2198
>      Project: Hibernate3
>         Type: Bug

>     Versions: 3.2.0.ga
>  Environment: JRE 1.5.0, SQLServer 2000, Window 2000
>     Reporter: David Chao

>
>
> Hi All,
> I have 3 tables with multiple primary keys and trying to get composite-id to work. Here are the tables.
> Table: tb_hl7MSH (regular id)
> Primary key: reportID
> Table: tb_hl7PID (composite-id mapping)
> Primary Key: reportID, setIDPID
> Table: tb_hl7OBR (composite-id mapping)
> Primary Key: reportID, setIDPID, setIDOBR
> <class name="com.sql.Hl7MSHData" table="tb_hl7MSH">
> <id name="MSHId" type="long" column="reportID" >
> <generator class="native"/>
> </id>
> <set name="HL7MSHtoPID" table="tb_hl7PID" lazy="true" cascade="all">
> <key column="reportID"/>
> <one-to-many class="com.sql.Hl7PIDData"/>
> </set>
> </class>
> <class name="com.sql.Hl7PIDData" table="tb_hl7PID">
> <composite-id name="PIDDataPK" class="com.sql.Hl7PIDDataPK">
> <key-property name="PIDId" column="setIDPID" type="long"/>
> <key-many-to-one name="MSHRec" class="com.sql.Hl7MSHData">
> <column name="reportID"/>
> </key-many-to-one>
> </composite-id>
> <set name="HL7PIDtoOBR" table="tb_hl7OBR" lazy="true" cascade="all">
> <key>
> <column name="reportID"/>
> <column name="setIDPID"/>
> </key>
> <one-to-many class="com.sql.Hl7OBRData"/>
> </set>
> </class>
> <class name="com.sql.Hl7OBRData" table="tb_hl7OBR">
> <composite-id name="OBRDataPK" class="com.sql.Hl7OBRDataPK">
> <key-property name="OBRId" column="setIDOBR" type="long"/>
> <key-many-to-one name="PIDRec" class="com.sql.Hl7PIDData">
> <column name="reportID"/> 
> <column name="setIDPID"/> 
> </key-many-to-one>
> </composite-id>
> </class>
> Code:
> public class Hl7MSHData implements Serializable {
> static final long serialVersionUID = 4334341L;
> private Long MSHId;
> private Set HL7MSHtoPID = new HashSet();
> public Hl7MSHData () {
> }
> public int hashCode() {
> return MSHId.hashCode();
> }
> public boolean equals(Object other) {
> if ( !(other instanceof Hl7MSHData) ) return false;
> Hl7MSHData c = (Hl7MSHData) other;
> return c.getMSHId().equals(MSHId);
> }
> } 
> public class Hl7PIDData implements Serializable {
> static final long serialVersionUID = 4334323L;
> private String id;
> private Hl7PIDDataPK PIDDataPK;
> private Set HL7PIDtoOBR = new HashSet();
> public Hl7PIDData () {
> this.id = java.util.UUID.randomUUID().toString();
> }
> public int hashCode() {
> System.out.println("PID Id: " + id.toString());
> return id.hashCode();
> }
> public boolean equals(Object other) {
> if ( !(other instanceof Hl7PIDData) ) return false;
> Hl7PIDData c = (Hl7PIDData) other;
> boolean flag = c.getPIDDataPK().getPIDId().equals(
> PIDDataPK.getPIDId()) &&
> c.getPIDDataPK().getMSHRec().getMSHId().equals(
> PIDDataPK.getMSHRec().getMSHId());
> System.out.println("PID Stat: " + flag);
> return flag;
> }
> ---- All the setter and getter method
> }
> public class Hl7PIDDataPK implements Serializable {
> static final long serialVersionUID = 4334323L;
> private String id;
> private Long PIDId;
> private Hl7MSHData MSHRec;
> public Hl7PIDDataPK () {
> this.id = java.util.UUID.randomUUID().toString();
> }
> public int hashCode() {
> System.out.println("PIDPK Id: " + id.toString());
> return id.hashCode();
> }
> public boolean equals(Object other) {
> if ( !(other instanceof Hl7PIDDataPK) ) return false;
> Hl7PIDDataPK c = (Hl7PIDDataPK) other;
> boolean flag = c.getPIDId().equals(PIDId) &&
> c.getMSHRec().getMSHId().equals(MSHRec.getMSHId());
> System.out.println("PID Stat: " + flag);
> return flag;
> }
> ---- All the setter and getter method
> }
> public class Hl7OBRData implements Serializable {
> static final long serialVersionUID = 4334342L;
> private Hl7OBRDataPK OBRDataPK;
> private String id;
> public Hl7OBRData() {
> this.id = java.util.UUID.randomUUID().toString();;
> }
> public int hashCode() {
> System.out.println("OBR Id: " + id.toString());
> return id.hashCode();
> }
> public boolean equals(Object other) {
> if ( !(other instanceof Hl7OBRData) ) return false;
> Hl7OBRData c = (Hl7OBRData) other;
> boolean flag = c.getOBRDataPK().getOBRId().equals
> (OBRDataPK.getOBRId()) &&
> c.getOBRDataPK().getPIDRec().getPIDDataPK().getPIDId().equals(
> OBRDataPK.getPIDRec().getPIDDataPK().getPIDId()) &&
> c.getOBRDataPK().getPIDRec().getPIDDataPK().getMSHRec().getMSHId().equals(
> OBRDataPK.getPIDRec().getPIDDataPK().getMSHRec().getMSHId());
> System.out.println("OBR Stat: " + flag);
> return flag; 
> }
> ---- All the setter and getter method
> }
> public class Hl7OBRDataPK implements Serializable {
> static final long serialVersionUID = 4334343L;
> private Long OBRId;
> private String id;
> private Hl7PIDData PIDRec;
> public Hl7OBRDataPK () {
> this.id = java.util.UUID.randomUUID().toString();
> }
> public int hashCode() {
> System.out.println("OBRPK Id: " + id.toString());
> return id.hashCode();
> }
> public boolean equals(Object other) {
> if ( !(other instanceof Hl7OBRDataPK) ) return false;
> Hl7OBRDataPK c = (Hl7OBRDataPK) other;
> boolean flag = c.getOBRId().equals(OBRId) &&
> c.getPIDRec().getPIDDataPK().getPIDId().equals(PIDRec.getPIDDataPK().getPIDId()) &&
> c.getPIDRec().getPIDDataPK().getMSHRec().getMSHId().equals(PIDRec.getPIDDataPK().getMSHRec().getMSHId());
> System.out.println("OBRPK Stat: " + flag);
> return flag; 
> }
> ---- All the setter and getter method
> }
> Main Class:
> public class build_objects {
> public static void main(String[] args) {
> try {
> build_objects mgr = new build_objects();
> mgr.createAndStoreEvent();
> HibernateUtil.getSessionFactory().close();
> } catch (ClassNotFoundException e) {
> e.printStackTrace();
> }
> }
> private void createAndStoreEvent() {
> // Session session = HibernateSessionFactory.getSession();
> Session session = HibernateUtil.getSessionFactory().getCurrentSession();
> session.beginTransaction();
> List ReportList = session
> .createQuery("from Hl7MSH")
> .list();
> // Iterating over the elements in the set
> Iterator ti = ReportList.iterator();
> while (ti.hasNext()) {
> Hl7Report ReportInfo = (Hl7Report) ti.next();
> //Object other = ti.next();
> //Hl7OBRDataPK obrdata = (Hl7OBRDataPK) other;
> //Long reportID = obrdata.getOBRId();
> // String reportID = temp[0].toString();
> //Hl7Report ReportInfo = (Hl7Report) session.load(Hl7Report.class,
> // reportID);
> System.out.println("REPORT Report ID: " + ReportInfo.getReportID());
> Set Hl7MSHSet = ReportInfo.getHl7RptMSH();
> // Iterating over the elements in the set
> Iterator it = Hl7MSHSet.iterator();
> while (it.hasNext()) {
> Hl7MSHData Hl7MSHInfo = (Hl7MSHData) it.next();
> Set Hl7PIDSet = Hl7MSHInfo.getHL7MSHtoPID();
> System.out.println("MSH ID:" + Hl7MSHInfo.getMSHId());
> System.out.println("MSH b:" + Hl7MSHInfo.getCm_Type());
> System.out
> .println("MSH c:" + Hl7MSHInfo.getDateTimeofMessage());
> // Iterating over the elements in the set
> Iterator itm = Hl7PIDSet.iterator();
> while (itm.hasNext()) {
> Hl7PIDData Hl7PIDInfo = (Hl7PIDData) itm.next(); 
> System.out.println("PID zz:" + Hl7PIDInfo.getGivenName());
> System.out.println("PID z1:"
> + Hl7PIDInfo.getPatientIDInternalID());
> Set HL7OBRSet = Hl7PIDInfo.getHL7PIDtoOBR();
> // Iterating over the elements in the set
> Iterator ito = HL7OBRSet.iterator();
> while (ito.hasNext()) {
> // Get element
> Hl7OBRData Hl7OBRInfo = (Hl7OBRData) ito.next();
> System.out.println("OBR Result Stat: "
> + Hl7OBRInfo.getResultStatus());
> }
> }
> }
> }
> session.getTransaction().commit();
> }
> }
> Was able to retrieve the first set of rows for all the tables but second set isn't coming thru for OBR. I get everything but the OBR records. I verify in the database that the row exist. Also, how do you "Select" or "Join" to a composite-id table when the ids are located in the PK table? I'm using SQLServer database. Any help would be appreciated. Thanks in advance.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list