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.
|