If I were you, I would change my entity classes. I think that would help a lot (I normally prefer annotations so you must forgive me if I write something wrong ....).
My sollution is:
Declare the mapping from the Presenter class to both the Event class and the Faculty class as what it is: A One to One or One to Many mapping. Don't save and manage the id's yourselves.
In Annotations:
Instead writting (Presenter class)
public void setEventId(int id)
do write (this change wouldn't change the db schema!)
@OneToOne
public void setEvent(Event event)
A benefit of the declaration above is, that you can declare the relation as bidirectional (this too doesn't change the db schema). So you can easily navigate in both directions without writing complex queries.
It would look like this (class Event):
@OneToOne(mappedBy ... ) <- I don't know the exact syntay without my book :-(, because I'm a beginner
public void setPresenter(Presenter presenter) ...
=> Hibernate will use the colum Presenter.ENVENT_ID (you already HAVE this column) to manage the mapping between Presenters and Events
If you do this changes, it will be easy to navigate between your classes. The db-schema won't change and hibernate will do all the (searching) work for you. Your hql statement will be very easy:
Select f
from Faculty f
where f.presenters.event.id = :event
Hopefully I was able to help you
Hoeft
|