-->
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.  [ 5 posts ] 
Author Message
 Post subject: Translate SQL to HQL
PostPosted: Wed Nov 16, 2005 11:50 am 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
Hi,

I have printed and read the hibernate doc but it is very poor in explanations about HQL (chapter 15).
So I managed to do simple queries but now I have one more complex that i'm not able to translate into HQL.

Here is the SQL query that I want into HQL :

Code:
select person, empServ, serv, emp
from Person person, EmpServ empServ, Serv serv, Emp emp
where person.idEmpServ = empServ.idEmpServ
   and empServ.idServ = serv.idServ
   and empServ.idEmp = emp.idEmp



And one more question (I'll give one credit for each...;o)):

Will I be able to retrieve an object for each column in my "select" clause.
I mean, I want to be able to retrieve the Person object, the EmpServ Object, the Serv object and the Emp object each time my query is satisfied..

Thanks in advance for help!

gaet'


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 12:44 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
For your first question, you want Session.createSQLQuery(" blah "), as opposed to Session.createQuery(" blah ")


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 1:09 pm 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
Thanks for reply denis,

but does this mean that it's not possible to translate my SQL into HQL?
I'm surprised because HQL is know to be powerful...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 1:32 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
disregard that. there is some good stuff in section 11.4 that is not in 15 - http://www.hibernate.org/hib_docs/v3/re ... e-querying . It appears you have a complex version of some of the stuff I know is in there. And you can definetly "retrieve an object for each column ", section 11.4.1.2 .


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 9:47 am 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
Thanks Denis,

This helps a little...and anyway, it help enough to help me to solve my problem...
for other readers that wants the solution, it is :
Code:
select person, empServ, serv, emp
from Person person
join person.empserv empserv
join empserv.ser serv
join empserv.emp emp


and then retrieve each object in the array returned (see chapter 11.4.1.2 for sample)

This solution is useful to retrieve object link up togheter instead of set lazy="false"....


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