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: Using aggregate function max(), min()..
PostPosted: Fri Jul 16, 2004 2:41 pm 
Newbie

Joined: Fri Jul 16, 2004 4:32 am
Posts: 4
Hi, people.

Please, advise me how to use aggregate function max() in query:

I have class myClass
Code:
Class myClass{
   int id;
   .. setters, getters
}

i create Query

Code:
Query query = sess.createQuery("select max(item.id) from myClass as item");


But how to get this value?? In Examples don't speak..

Code:
int max = ??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 3:02 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://www.hibernate.org/hib_docs/refer ... hql-select

you have to understand collection of object[]
and know how to cast the result (in object[]) AND each part of your query

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 12:23 pm 
Newbie

Joined: Wed Feb 09, 2005 12:00 pm
Posts: 2
The documentation on hql shows how to write the queries; however, no where does it show how to get the results of something like

select count(d.id),sum(d.numPages) from document d where d.numPages > 1

_________________
Suzanne
"Reality is merely an illusion, albeit a very persistent one." - Einstein


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 12:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
It does, right here: http://www.hibernate.org/hib_docs/refer ... larqueries


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 9:46 am 
Newbie

Joined: Fri Dec 09, 2005 4:57 am
Posts: 7
michael wrote:


The example says:

Code:
Iterator results = sess.iterate(
        "select cat.color, min(cat.birthdate), count(cat) from Cat cat " +
        "group by cat.color"
);
while ( results.hasNext() ) {
    Object[] row = results.next();
    Color type = (Color) row[0];
    Date oldest = (Date) row[1];
    Integer count = (Integer) row[2];
    .....
}


However, the following worked for me:

Code:
Iterator results = sess.iterate(
        "select cat.color, min(cat.birthdate), count(cat) from Cat cat " +
        "group by cat.color"
);
while ( results.hasNext() ) {
    Object[] row = (Object[])results.next();
    Color type = (Color) row[0];
    Date oldest = (Date) row[1];
    Integer count = (Integer) row[2];
    .....
}


Hope that helps,

Rauf


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.