-->
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: basic HQL question about elements() function
PostPosted: Fri Feb 23, 2007 2:26 pm 
Newbie

Joined: Fri Feb 23, 2007 2:05 pm
Posts: 1
I can't seem to able to write an HQL query (I am new to HQL) that does the following:
find all events that involve a certain medication

events have a many eventMedicationRoutes (pairs of medications and routes).

Attempted Query
Code:
SELECT FROM ss.db.event.Event as Event WHERE :medicationId   IN elements(event.eventMedicationRoutes.medicationid)


Error: it wants my to wrap another elements() function around soemthing???

Note: I can not put anything in the FROM clause (this is a dynamically generated query and this is just one of the conditions; the FROM clause would get very large if I'd put all the joins in there)

I looked throuh the manuals and googled the problem as well as I could to no avail.

Any hint how to change my query????

Hibernate version: 2.1.6

Mapping documents:

event.hbm.xml fragment
Code:
        <set name="eventMedicationRoutes" table="eventmedicationroute" lazy="true" cascade="all" sort="unsorted">
            <key column="eventid" foreign-key="eventmedicationroute_fk_1"/>
            <composite-element class="ss.db.event.MedicationAndRoute">
                <many-to-one name="medication" column="medicationid" class="ss.db.dict.Medication" foreign-key="eventmedicationroute_fk_2"/>
                <many-to-one name="drugRoute" column="drugrouteid" class="ss.db.dict.DrugRoute" foreign-key="eventmedicationroute_fk_3"/>
            </composite-element>
        </set>


exception that occurs:
org.springframework.orm.hibernate.HibernateQueryException: expecting 'elements' or 'indices' after: id [Select event.status, event.id, event.occurrenceDate, event.mrn, event.patientName from ss.db.event.Event as event where :medicationId in elements(event.eventMedicationRoutes.medicationid)]; nested exception is net.sf.hibernate.QueryException: expecting 'elements' or 'indices' after: id [Select event.status, event.id, event.occurrenceDate, event.mrn, event.patientName from ss.db.event.Event as event where :medicationId in elements(event.eventMedicationRoutes.medicationid)]

Name and version of the database you are using:
PostgreSql 8.1 right now for development; others later

Code:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 10:52 am 
Newbie

Joined: Thu May 12, 2005 10:40 am
Posts: 16
don't know how you mapped your ID-Feld within class Medication.
I suppose it's named Id.
Then the following query should run.

Code:
FROM ss.db.event.Event e
WHERE exists (select eMR.medication.Id FROM elements(e.eventMedicationRoutes) eMR WHERE eMR.medication.Id = :medicationId )


i think there's no way to use the mapped column 'medicationid' directy within the query.

*g
Helmut


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.