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.  [ 4 posts ] 
Author Message
 Post subject: Need help converting complex SQL -> HQL
PostPosted: Tue Aug 09, 2005 11:04 am 
Newbie

Joined: Fri Oct 17, 2003 11:31 am
Posts: 19
I'm running Hibernate 3.0.5 with Oracle 9i.

I'm hoping there's an HQL guru out there who can help me with this query.

I'm new to HQL and am running into problems converting the query below into an appropriate HQL query. I have objects generated for each of the tables involved in the query.

I'm looking for guidance on how to convert complex queries like the one listed below.
Part of my confusion is regarding how to handle the concatenation of columns into a single column using HQL.

Any help / suggestions would be greatly appreciated.

Thanks,

Quenten

Code:
SELECT 
dl.worker_dn,     
dl.worker_name,     
dl.queue_item_status,   
dl.create_date,
dl.document_review_queue_item_eid,     
drq.document_review_queue_eid,   
drq.queue_name,   
drq.result_query,   
drq.queue_descr,   
d.xinstrument_no reception_no,   
d.xtime_received date_filed,   
ld.did, ld.multi_seq,
ld.document_type, pr.grantor,  pe.grantee     
,   r.firstname||' '||r.lastname returnee_name,   
r.street_number||' '||r.street_name||' '||r.suite||' '||r.city||' '||r.state||' '||r.zipcode||decode(r.ZIPCODE_EXT,NULL,'','-'||r.zipcode_ext) RETURNEE_ADDR   
FROM   (   select d1.did   
       ,d1.xinstrument_no ,r.ddoctype   
      ,rdi.document_review_queue_eid   ,rdi.DOCUMENT_REVIEW_QUEUE_ITEM_EID,rdi.worker_dn,rdi.worker_name,   
rdi.queue_item_status,rdi.create_date   
          from docmeta d1 , docmeta d2, revisions r,document_review_queue_item  rdi   
         where d1.xinstrument_no = d2.xinstrument_no   
           and d1.did = r.did and r.dreleasestate != 'O'   
         and r.ddoctype <>'TD1000'       
           and d2.did =rdi.document_id   
         and rdi.document_review_queue_eid=?) dl     
,document_review_queue drq   
,docmeta d   
,dc_opr_logical_document ld   
,dc_opr_returnee r     
,(select did, multi_seq,firstname||' '||lastname grantor   
    from dc_opr_party       
   where name_seq =1     
     and name_type= 'R' ) pr, (select did, multi_seq,firstname||' ' ||lastname grantee from dc_opr_party     
   where name_seq=1   
     and name_type= 'E' ) pe     
WHERE  r.did = dl.did     
   and pr.DID = dl.did         
   and pr.multi_seq = 0       
   and pe.did =  dl.did         
   and pe.multi_seq = 0   
   and ld.did = dl.did     
   and d.did = dl.did     
   and drq.document_review_queue_eid = dl.document_review_queue_eid   
and ld.multi_seq = 0     
and r.return_seq =1     
and drq.document_review_queue_eid = ? 
  order by d.xinstrument_no


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 11:09 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Don't expect me to convert your whole query to HQL. :)

Concatenation can be done as in your example using columnA || columnB or using concat(columna, columnB).

Read the documentation for more information on HQL expressions:
http://www.hibernate.org/hib_docs/v3/re ... xpressions

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 9:11 am 
Newbie

Joined: Fri Oct 17, 2003 11:31 am
Posts: 19
Thanks for the help with the concat of the columns. The problem I'm running into now is this part of the query :

Code:
FROM   (   select d1.did   
       ,d1.xinstrument_no ,r.ddoctype   
      ,rdi.document_review_queue_eid   ,rdi.DOCUMENT_REVIEW_QUEUE_ITEM_EID,rdi.worker_dn,rdi.worker_name,   
rdi.queue_item_status,rdi.create_date   
          from docmeta d1 , docmeta d2, revisions r,document_review_queue_item  rdi   
         where d1.xinstrument_no = d2.xinstrument_no   
           and d1.did = r.did and r.dreleasestate != 'O'   
         and r.ddoctype <>'TD1000'       
           and d2.did =rdi.document_id   
         and rdi.document_review_queue_eid=?) dl     
,document_review_queue drq 


I'm not sure how to handle a sub-select in the FROM clause of the query. Since there are 3 tables involved in that sub-select I don't think I can just do a JOIN on those tables.

Any ideas / suggestions on how to handle sub-selects in the FROM clause?

Thanks,

Quenten


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 9:21 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
HQL does not support subselects in the FROM clause.
You'll have to think about an alternative way doing this in SQL. Maybe you're able to make some joins in order to get the same result.

Best regards
Sven


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