-->
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: how to do it in HQL query
PostPosted: Mon Sep 15, 2008 9:23 am 
Newbie

Joined: Mon Sep 15, 2008 8:44 am
Posts: 3
Hi All,
am new to hibernate , am writing applications in java and i have started using hibernate ,

can i do the following query using sqlquery ( where am using mysql)

Code:
select m.operator,s.scode,a.OCCASIONTYPE ,count(*) from msg_info m,shortcode s,operator op,account a where m.scode_id=s.id and m.operator=op.operator and m.accid=a.id and m.operator in ('SABAFON','mobi') and s.scode in ('4646','4050') and a.occasiontype in ('wedding','anniversary')
group by m.operator,s.scode,a.OCCASIONTYPE;


( by the the way the above tables joins 4 tables).
i have asked one of my friends and she said u have to do it using HQL with criteria , can any one convert it to HQL query .. PLZ help me am new to hibernate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 12:28 pm 
Newbie

Joined: Mon Sep 15, 2008 8:44 am
Posts: 3
Hi All,

Any one to help me please am waiting for a reply .........


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 16, 2008 5:37 am 
Newbie

Joined: Mon Sep 15, 2008 8:44 am
Posts: 3
Hi thanks to all ,

I know that i did not get reply from anyone of you but i have received your prays to God to help me ... so thanks alot for all of you ...


I have made the query using Native Sql and here the piece of code (if anyone want to know how i wrote)


Code:
String queryString = "SELECT m.operator as operator,sc.scode as shortCode,a.occasionType as occasionType,count(*) as total from msg_info m ,account a,operator op,shortcode sc where  m.ACCID=a.ID and m.operator = op.operator and m.scode_id = sc.id and op.id in "+ subquery + " and sc.id in "+ subquery2 + " group by m.operator ,m.scode_id ,a.occasionType ";

List list = session.createSQLQuery(queryString).addScalar("operator", Hibernate.STRING).addScalar("shortCode", Hibernate.STRING).addScalar("occasionType", Hibernate.STRING).addScalar("total", Hibernate.LONG).list();
   
for(Iterator it1 = list.iterator();it1.hasNext();)
{
   Object[] row = (Object[]) it1.next();
   System.out.println("operator ----- >>> > > > > >: " + row[0]);
   System.out.println("short code ----- >>> > > > > >" + row[1]);
   System.out.println("occasion type ----- >>> > > > > >"+ row[2]);
   System.out.println("total  ----- >>> > > > > > " + row[3]);
}



it took me long hours to produce the above code....but at the last i got and it is working fineeeeeeeeee.


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.