-->
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: How to query part of fields with named SQL query?
PostPosted: Sun Oct 09, 2005 10:28 pm 
Newbie

Joined: Sun Oct 09, 2005 10:18 pm
Posts: 2
I just want to user'name and count .How to get it with Hibernate 2.1.6?

<sql-query name="QueryUser">
<![
CDATA[
select user.grade,count(*) count from User user
where user.name like 'A%' ]
]>
<return alias="user" class="???"/> (Here how to write)
</sql-query>

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 12:49 am 
Newbie

Joined: Fri Apr 01, 2005 5:21 am
Posts: 11
Why do you want to use an sql-query?
You can use an HQL named query.

<query name="QueryUser">
select new YourClass'sName (user.grade,count(*) count from User user
where user.name like 'A%' group by user.grade
</query>

If you DO wnat to use an sql-query,

<sql-query name="QueryUser">
<return alias="user" class="YourClassName"/>
select new YourClass'sName (user.grade,count(*) count from User user
where user.name like 'A%' group by user.grade
</sql-query>

In the class atribute, you have to write the complete name of the class, starting from the base folder, say, com.yahoo.User


Top
 Profile  
 
 Post subject: Thanks.
PostPosted: Mon Oct 10, 2005 12:56 am 
Newbie

Joined: Sun Oct 09, 2005 10:18 pm
Posts: 2
As your way, I have to create a new class to contain the query result. But I just want to query it as a report to display. Does I have another simple way? Can I get a Object[] array to contain the query result?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 1:10 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
you can do it, but it is better that you use hql

it is little strange on start, but it is very power


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 12:03 pm 
Newbie

Joined: Fri Apr 01, 2005 5:21 am
Posts: 11
<query name="QueryUser">
select new map (user.grade as grade,count(*) as count ) from User user
where user.name like 'A%' group by user.grade
</query>

This will return a Map with aliases as key and the selected values as the corresponding values.


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.