-->
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.  [ 6 posts ] 
Author Message
 Post subject: How convert this native sql to hql?
PostPosted: Wed Aug 25, 2004 8:06 am 
Newbie

Joined: Sat Aug 21, 2004 12:15 am
Posts: 3
Hibernate version:2.1.6
select count(a.name),'a',a.createdate from tbl a group by a.createdate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 11:49 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
Is the same.
Code:
select count(a.name), a.createdate from MyClass a group by a.createdate

However I don't know how to insert a constant in the select clause, but I think that 'a' can be managed at code level


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 9:01 pm 
Newbie

Joined: Sat Aug 21, 2004 12:15 am
Posts: 3
for example?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 3:20 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
Why you need the constant in the select clause?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 12:43 am 
Newbie

Joined: Sat Aug 21, 2004 12:15 am
Posts: 3
because I'll return a list for a jsp named "commonlist.jsp ",and column is variable,so i insert some constant to keep it .sorry ,my english is so poor!^_^


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 2:57 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
If I have understood your problem you can load only the results from the hql and then concatenating the strings:
Code:
String[] results = null;
           
Query q = session.createQuery("select count(a.name), a.createdate from MyClass a group by a.createdate");
List list = q.list();
           
results = new String[list.size()];
for(int i = 0; i < list.size(); i++) {
    Object[] row = (Object[])list.get(i);
    results[i] = row[0] + "a" + row[1];
}


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