-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL Join ?
PostPosted: Fri Nov 04, 2011 3:46 pm 
Newbie

Joined: Tue Jan 05, 2010 2:33 pm
Posts: 15
I have a Table Employee

I have a table Competency

Competency contains employee id.

How can I return my list of employees and join the count of competencies to each employee object returned in the list? Using hql does anyone have a good example of how to do this?

Thanks

Spunog


Top
 Profile  
 
 Post subject: Re: HQL Join ?
PostPosted: Sat Nov 05, 2011 9:56 am 
Newbie

Joined: Tue Jan 05, 2010 2:33 pm
Posts: 15
I think I have found a solution for this. I will use .createSQLQuery () and use the following native SQL :

Code:
select count(ec.INT_ID) as count, e.INT_ID as eid from LU_EMPLOYEE_TO_COMPETENCY ec join TBL_EMPLOYEE e on e.INT_ID = ec.INT_EMPLOYEE_ID where ec.INT_COMPETENCY_ID in (select (pc.INT_COMPETENCY_ID) from LU_COMPETENCY_TO_PROFILE pc where pc.INT_PROFILE_ID="8") GROUP BY eid


And then pull the values out using this :


Code:
.addScalar("count",Hibernate.INTEGER).addScalar("eid",Hibernate.INTEGER).list();




Code:
Object[] obj = llist.get(0);
     
      System.out.println(obj[0]);
      System.out.println(obj[1]);


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

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.