I’m trying to get a collection of objects using Hibernate, but I am not sure how to formulate the query as I can’t (or don’t know how) start from the object that I want to be returned.
I have 3 classes:
Participant
Event
EventRegistration
The connection between them is made by EventRegistration which has a many-to-one relationship with Event and many-to-many relationship with Participant. It looks like this:
EventRegistration.participants
EventRegistration.event
I would like to write a query using HSQL or Criteria API to get me all participants for a specific event.
Basically that would look more or less like:
from EventRegistration er inner join er.event as ev inner join er.participants as p where ev.id=?
Anyway, the above query returns an Object array containing one of each of those objects (like Object[]{EventRegistration, Event, Participant}.
I did try to find how to do this over the net, but all examples start from the returned object. Unfortunately I can’t start from the Participant object as there is no direct connection from it to EventRegistration or Event.
Any idea how to make it return only the list of Participants?
Thanks.
Use a select clause: