-->
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: Join Table many-to-one issue - join by non-primary key
PostPosted: Tue Jun 29, 2010 1:09 pm 
Newbie

Joined: Mon May 03, 2010 6:36 pm
Posts: 5
Hi

My main table is PTNT_DATA_MSRMNT_CLCTN & join table is PTNT_PRCTC_PRFMNC_YR. I want to join these 2 tables by a non-primary key (in the main table), but it does not work.

Tables:
Code:
PTNT_DATA_MSRMT_CLCTN :
PTNT_DATA_MSRMNT_CLCTN_ID (PK)
PTNT_PRCTC_PRFMNC_YR_ID
DEMO_PRCTC_DATA_CLCTN_PRD_ID

PTNT_PRCTC_PRFMNC_YR:
PTNT_PRCTC_PRFMNC_YR_ID (PK)
DEMO_PRCTC_ID
DEMO_PRFMNC_YR_ID
PTNT_ID


Mapping:
Code:
<class name="PatientDataMeasurementCollection" table="PTNT_DATA_MSRMNT_CLCTN">
    <id name="patientDataMeasurementCollectionId"
        column="PTNT_DATA_MSRMNT_CLCTN_ID"
        type="long">
      <generator class="assigned" />
    </id>
    <property name="demoCollectionPeriodId"
              column="DEMO_PRCTC_DATA_CLCTN_PRD_ID"
              type="long" />
    <property name="patientPracticePerformanceYearId"
            column="PTNT_PRCTC_PRFMNC_YR_ID"
            type="long" />

    <join table="PTNT_PRCTC_PRFMNC_YR"
          optional="false">
      <key column="PTNT_PRCTC_PRFMNC_YR_ID" unique="true" property-ref="patientPracticePerformanceYearId" />
      <many-to-one name="patient"
                   column="PTNT_ID"
                   not-null="true"
                   fetch="join" />
    </join>
</class>


Now I need to join by PTNT_PRCTC_PRFMNC_YR_ID on these 2 tables. But the generated SQL has this in the where clause:

where this_.PTNT_DATA_MSRMNT_CLCTN_ID=this_1_.PTNT_PRCTC_PRFMNC_YR_ID.

But It should rather be
this_.PTNT_PRCTC_PRFMNC_YR_ID=this_1_.PTNT_PRCTC_PRFMNC_YR_ID.

Hibernate version : 3.2.7.ga

Can you guys help me on this. Hope I have made my issue clear & is understandable.

Thanks

Harish


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.