Hi,
In my application I use hibernate criteria to implement search in my dao's. At this moment I don't know how to construct my search method for a specific search expression which is simple in sql and hql.
The hql expression is:
Code:
"select distinct person from Team as team, Person as person where team.coach = person"
the sql expression is:
Code:
"select p.* from person p, team t where t.coach_person_id=p.person_id;"
I started my Criteria implementation with:
Code:
Criteria criteria = createCriteria(Person.class, "p");
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Team.class,"t");
detachedCriteria.add(Restrictions.eqProperty("t.coach", "p"));
...
?? This is my question: How to combine detachedCriteria and criteria to implement the hql expression above?
...
persons = criteria.list();
background:
I'm creating a members administration app for my baseball club. There's a Person entity and a Team entity. The Team entity has a reference (foreignkey) to Person entity named coach. There is a Search page to search for a team by different criteria (search by name, search by coach, search by season etc.). To search by coach, a user can select a person from a combo. Of course, I don't want this combo to contain all persons, but only persons who are coach of some team. That's why I need a dao finder method to find all persons who are coach.
Is it possible to use the Hibernate Criteria api for this search functionality?
Thanks
Marnix