-->
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: common practice : generating a multiple row/column report
PostPosted: Mon May 01, 2006 10:43 pm 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
Hibernate version: 3.1.3

Hi,
would like to seek some advice on how to support this:
- i need to generate a multi row/column report (with the # of items match row and column condition).

- I am thinking of using criteria API to dyunamically generate the query
the logic seems like this one:

for (every row condition) {
for (every column condition) {
create the criteria;
return criteria.list();
}
}


Is this a common practice ? any better way of handling a report ?

thanks for reading !
lixin


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 11:26 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Normally reports don't use managed objects, just scalars. Reports tend to deal with large numbers of rows, or at least larger numbers than you'd normally deal with for on-screen queries, so saving memory is good, and also saving the time required to build managed objects. They're also usually fire-and-forget: you don't need links to other objects, row identifiers, or anything other than the data you'll be printing. So usually, HQL's select new syntax is enough (if you want to put each row into a bean-like object), or else you could use an sql-query with the required columns defined using return-scalar elements.

select new is described in the ref docs, section 14.5. sql-query and return-scalar are in section 16.3.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 7:57 pm 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
thanks. these are all new to me.

a question:

since the report only shows the number of matched items, shouldn't I use a query string like this:

select count (*) from Item where ....



btw, the reason why I was thinking of using Criteria API is that the report will be defined at runtime and can be updated at any time. So I thought Criteria API is a good candidate since I can build the query at runtime also.

any comments ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 11:07 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Yes, select count(*) is a common query for reports.

Criteria can handle report-style queries, making use of the Projection interface. The reason that reports are usually not written using Criteria is because most reports are always the same. This doesn't apply in your case, as the shape of the report is defined at runtime, so Criteria is appropriate for you.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 06, 2006 6:52 pm 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
thanks !


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.