-->
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.  [ 3 posts ] 
Author Message
 Post subject: Join with relationship
PostPosted: Fri Aug 12, 2011 12:20 am 
Newbie

Joined: Thu Aug 11, 2011 3:46 am
Posts: 3
Hi everybody,
I have a query with SQL following:

select E.ID, E.FIRST_NAME, E.LAST_NAME, E.LOCATION, E.SALARY
from Employee E, Department D
where E.DEPT_ID = D.ID
and D.Name='Manager'

How do I write this query in HQL ?
Please help me !
Thanks


Top
 Profile  
 
 Post subject: Re: Join with relationship
PostPosted: Mon Aug 15, 2011 12:33 pm 
Newbie

Joined: Mon Aug 15, 2011 12:25 pm
Posts: 1
I'm not an expert but I believe this is the syntax assuming you want an Employee object returned and have properly mapped the relation:

from Employee as e
left join e.dept_id as d (I believe the "dept_id" is the member name of your pojo entity)
where d.name='manager'




http://docs.jboss.org/hibernate/core/3. ... ryhql.html


Top
 Profile  
 
 Post subject: Re: Join with relationship
PostPosted: Tue Aug 16, 2011 7:39 am 
Newbie

Joined: Wed May 11, 2011 12:26 am
Posts: 1
// Assume session already exists and want to retrive all fileds of employee record
Query qry = session.createQuery("select employee from Employee employee join Department dept where dept.name=:dname");
qry.setParameter("dname","Manager");
List<Employee> empList = qry.list();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.