-->
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: Recommended practice for querying only some fields for objs.
PostPosted: Mon Jul 12, 2004 10:42 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
I have a situation where I am loading a HTML page which lists many rows in a table. Each row represents an object called Schedule. I use Hibernate to manage persisting Schedule objects. Each Schedule has a Set collection and other String properties.

On my HTML table I only want to list 2 properties and the COUNT of the internal Set because it is taking quite a while for Hibernate to fully load all the Schedule objects which is what I have at the moment.

However, I do not know how to approach this problem because when I get to the JSP to render the HTML I want to iterate over a List to output the rows.

Do I have to create another object with only the 2 fields I want and an int for the count and then populate this using a specific HQL query? What is the general practice in this kind of situation?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 10:45 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Code:
9.3.1. Scalar queries
Queries may specify a property of a class in the select clause. They may even call SQL aggregate functions. Properties or aggregates are considered "scalar" results.

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];
    .....
}
Iterator iter = sess.iterate(
    "select cat.type, cat.birthdate, cat.name from DomesticCat cat"
);
List list = sess.find(
    "select cat, cat.mate.name from DomesticCat cat"
);
[quote]

http://www.hibernate.org/hib_docs/reference/en/html/manipulatingdata.html#manipulatingdata-scalarqueries[/quote]

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 10:49 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
thanks. typo by the way .. should be...

Object[] row = (Object[]) results.next();


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.