-->
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: Help Required for createSQLQuery()
PostPosted: Thu Aug 24, 2006 10:37 am 
Newbie

Joined: Thu Apr 27, 2006 9:56 am
Posts: 14
Location: Hyderabad
Hi..

I am trying to reteive columns for diffent tables within an SQL query.

For example:

Let EMPLOYEE, DEPT are two tables.

My Query is as follows:

select emp.empID, dept.deptID from EMPLOYEE emp join DEPT dep on emp.deptID = dep.deptID

how should my createSQLQuery should be and once i get my list how can I retrieve empId and deptId.

Thanks & Regards
Ramadevi K


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 2:56 pm 
Regular
Regular

Joined: Fri Aug 18, 2006 2:40 pm
Posts: 51
Location: Metz, France
select emp.id, dpt.id from Employee emp join emp.dept dpt

_________________
Denis
Don't forget to rate ... thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 25, 2006 5:01 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Code:
String sql = "select emp.empID, dept.deptID from EMPLOYEE emp join DEPT dep on emp.deptID = dep.deptID";
List<Object[]> ids_list = session.createSQLQuery(sql).list();
for(Object[] ids : ids_list) {
   //ids[0] is empID
   //ids[1] is deptID
}


Please, don't forget to rate.


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.