-->
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: Java-Hibernate-Newbie: How do I acces the values from this l
PostPosted: Tue Apr 13, 2010 6:23 pm 
Newbie

Joined: Sun Apr 11, 2010 7:22 am
Posts: 4
I have this class mapped

Code:
@Entity
@Table(name = "USERS")
public class User {
private long id;
private String userName;
}


and I make a query:

Code:
Query query = session.createQuery("select id, userName, count(userName) from User order by count(userName) desc");
            return query.list();


How can I access the values(the result of the count) returned by the query?
I mean, how should I treat the query.list()? As a User or what?


If I try to cast the query.list.get(int) to User, I receive an exception.


Top
 Profile  
 
 Post subject: Re: Java-Hibernate-Newbie: How do I acces the values from this l
PostPosted: Tue Apr 13, 2010 10:21 pm 
Newbie

Joined: Tue Apr 13, 2010 2:23 am
Posts: 7
no reply! now!
◎◎◎◎

_________________
Hobbies Sports: Playing golf!

ping g10 driver*
ping g10 irons|


Top
 Profile  
 
 Post subject: Re: Java-Hibernate-Newbie: How do I acces the values from this l
PostPosted: Wed Apr 14, 2010 2:34 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Each entry in the list is an Object[] with the fields from the select statement in the same order. See section 10.4.1.3 in http://docs.jboss.org/hibernate/stable/ ... e-querying


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.