-->
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: New to Hibernate question about Hql query
PostPosted: Fri Mar 26, 2010 3:57 pm 
Newbie

Joined: Fri Mar 26, 2010 3:43 pm
Posts: 2
Hi everybody.
I have a question about hql queries.
Here is my code.

Code:
return session.createQuery(
         "SELECT DISTINCT APFEE.FEEDESC, LicenseItem.APNO, CONTACT.CNTCTFIRST || ' '|| CONTACT.CNTCTLAST AS NAME, "+
         "CONTACT.DAYPHN, CONTACT.CITY, CONTACT.STATE,CONTACT.ZIP, APFEE.QTY, LicenseItem.APKEY,"+
         "LicenseItem.EXPDTTM, APFEE.AMT, CONTACT.ADDR1 || ' '|| CONTACT.ADDR2 AS ADDR "+
         "FROM LicenseItem, APAPL, APFEE, APDEFN, CONTACT "+
         "WHERE  LicenseItem.APKEY=APAPL.APKEY) AND LicenseItem.APKEY=APFEE.APKEY) AND "+
         "(LicenseItem.APDEFNKEY=APDEFN.APDEFNKEY) AND (APAPL.CNTCTKEY=CONTACT.CNTCTKEY) AND "+
         "APFEE.STAT='U' AND LicenseItem.INACTVFLAG='N' AND APAPL.PRIM='Y' AND   TRIMLicenseItem.APNO)= '?' ")
         .setString(0, licenseNumber);
         }
      })

so here is the question I realize that I need the class name in the from statement for the LicenseItem table, but I don't know about APAPL, APFEE, APDEFN, CONTACT. This code is returning the result in the LicenseItem class, so do I need separate classes for APAPL, APFEE, APDEFN, CONTACT and the hbml.xml files too?
I just want to get the result back in the LicenseItem class. Thanks for your help


Top
 Profile  
 
 Post subject: Re: New to Hibernate question about Hql query
PostPosted: Fri Apr 23, 2010 1:51 pm 
Newbie

Joined: Fri Mar 26, 2010 3:43 pm
Posts: 2
I was thinking that I would need to run a sub query because I am just getting the select. I will never updated these tables, just read from them.


Top
 Profile  
 
 Post subject: Re: New to Hibernate question about Hql query
PostPosted: Sun Apr 25, 2010 2:43 pm 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
If you want to use Hibernate (HQL) you will need to map the objects you want to use.

Take a look at native SQL. I haven't used it before, but I believe you can execute native SQL queries and use them as result sets.


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.