-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria equivalent of a (simple) hql query
PostPosted: Mon Mar 15, 2010 7:07 am 
Newbie

Joined: Mon Mar 15, 2010 4:41 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.