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: