-->
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: HQL select statement (newbie question)
PostPosted: Tue Jun 14, 2005 5:28 pm 
Beginner
Beginner

Joined: Thu Jun 09, 2005 2:33 pm
Posts: 30
If i execute an HQL select statement, referencing the pojo and it's properties, do I then have to iterate through the results and populate the pojo properties?

ex.
Iterator results = sess.createQuery(
"select cat.color, min(cat.birthdate), count(cat) from Cat cat " +
"group by cat.color")
.list()
.iterator();

while ( results.hasNext() ) {
Object[] row = results.next();
Color type = (Color) row[0];
Date oldest = (Date) row[1];
Integer count = (Integer) row[2];
.....
}

So in the while loop would I populate the pojo with the values from the Object[]?


Top
 Profile  
 
 Post subject: Re: HQL select statement (newbie question)
PostPosted: Tue Jun 14, 2005 7:23 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
graeder wrote:
If i execute an HQL select statement, referencing the pojo and it's properties, do I then have to iterate through the results and populate the pojo properties?

ex.
Iterator results = sess.createQuery(
"select cat.color, min(cat.birthdate), count(cat) from Cat cat " +
"group by cat.color")
.list()
.iterator();

while ( results.hasNext() ) {
Object[] row = results.next();
Color type = (Color) row[0];
Date oldest = (Date) row[1];
Integer count = (Integer) row[2];
.....
}

So in the while loop would I populate the pojo with the values from the Object[]?


No. The collection will be fully populated POJO objects.

You might want to read the docs and do some tutorials before you post any more questions because most people would tell you that now.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 7:37 pm 
Beginner
Beginner

Joined: Thu Jun 09, 2005 2:33 pm
Posts: 30
Actually, I've read a book, and have been looking through the docs. Certain things just aren't clear yet, which is why I'm asking.


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.