-->
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: cannot query from >2 tables
PostPosted: Wed Mar 02, 2011 5:36 pm 
Newbie

Joined: Wed Mar 02, 2011 4:56 pm
Posts: 1
hi, i have a problem in query using hibernate.
i already have a sql query from four tables, and its successfully tested in my oracle (i use oracle db).
Code:
select e.empidentitynum
from (((Hrm_Employee e join Hrm_Officialhistory o on e.empid = o.empid)
join Hrm_Jobtitles j on j.jobtitleid = o.newjobtitle )
join Hrm_Jobspecification s on s.jobspecid = j.jobspecid )
where s.jobspecname like 'Manager'


but when i use it in createSQLQuery, the test failed.
Code:
Query q =  session.createSQLQuery(
                    "select e.empidentitynum"+
                    "from (((Hrm_Employee e join Hrm_Officialhistory o on e.empid = o.empid)"+
                    "join Hrm_Jobtitles j on j.jobtitleid = o.newjobtitle )"+
                    "join Hrm_Jobspecification s on s.jobspecid = j.jobspecid )"+
                    "where s.jobspecname like 'Manager'")
                    .addEntity(HrmEmployee.class)
                    .addEntity(HrmOfficialhistory.class)
                    .addEntity(HrmJobspecification.class)
                    .addEntity(HrmJobtitles.class);


so i make a simple native query from 2 tables and it work.
then i make a simple native query from 3 tables and it doesn't work.

how can i make a query from more than 2 tables?

thanks a lot before.


Top
 Profile  
 
 Post subject: Re: cannot query from >2 tables
PostPosted: Wed Mar 09, 2011 7:14 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Hi,

You should be able to join as many tables as you want.
The only restriction is that you cannot join 2 tables that are not linked through the hbm mapping!
Your HQL query should look like this :
Code:
select e.empidentitynum from Hrm_Employee e join e.officialHistory

You don't even need to specify a join condition, Hibernate will automatically create it from your hbm mapping.


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.