-->
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.  [ 2 posts ] 
Author Message
 Post subject: loading a collection via sql-query without a FK to the table
PostPosted: Thu Nov 01, 2007 2:22 pm 
Newbie

Joined: Wed Oct 24, 2007 2:04 pm
Posts: 2
I need to load an Observable object and populate the patientRules Set with a named query that returns a list of PatientRule objects... The Observable table and PatientRule table have no direct database relationship, and therefore no FK relationship.


Observable.java
long observableSeq
String name
String displayText
Set patientRules

PatientRule.java
long patRuleId
String gender
int ageLow
int ageHigh


here is a snippet from my Observable.hbm.xml file
...
...
<set name="patientRules" inverse="true" lazy="true">
<key>
<column name="PAT_RULE_ID" precision="10" scale="0" not-null="true" />
</key>
<one-to-many class="com.mckesson.documentation.PatientRule" />
<loader query-ref="loadPatientRulesForObservable"/>
</set>
</class>
<sql-query name="loadPatientRulesForObservable">
<load-collection alias="pRule" role="com.mckesson.documentation.Observable.patientRules"/>
<![CDATA[SELECT pRule.PAT_RULE_ID,
pRule.PAT_RULE_NAME,
pRule.GENDER,
pRule.AGE_LOW,
pRule.AGE_LOW_UNIT,
pRule.AGE_LOW_OPERATOR,
pRule.AGE_HIGH,
pRule.AGE_HIGH_UNIT,
pRule.AGE_HIGH_OPERATOR,
pRule.CHANGE_DT,
pRule.CREATION_DT
FROM ED_PATIENT_RULE pRule,
ED_LABEL label,
ED_HIER hier
WHERE label.RES_SEQ = ?
AND label.CAT_SEQ = 0
AND label.LABEL_SEQ = hier.PARENT_ID
AND hier.PARENT_TYPE = 'L'
AND hier.CHILD_TYPE = 'SP'
AND hier.CHILD_ID = PAT_RULE_ID]]>
</sql-query>


The problem is this query returns the results as seen in hibernate DEBUG mode, however it does not set the resulting PatientRule objects into the Observable.patientRules. I believe this is because the underlying key specified above(PAT_RULE_ID) does not exist in the ED_PATIENT_RULE table, not a FK relationship.

Is there any way to load the associate PatientRule objects without setting the one-to-many and key attributes? Basically I just want to load the Observation.patientRules with a list of PatientRule objects, and again there is no direct database relationship between the two, and as a result there is no FK relationship.

Is is possible to load a unrelated Set of objects just via the mapping and the sql-query, or does there need to be a FK relationship?

Feel free to ask ?'s as I'm not certain If I fully explained this to the degree in which it would make sense to an outsider.


Top
 Profile  
 
 Post subject: did you solve this issue?
PostPosted: Mon Apr 21, 2008 2:19 pm 
Regular
Regular

Joined: Thu Sep 09, 2004 6:46 pm
Posts: 96
did you solve this issue?


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