-->
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.  [ 4 posts ] 
Author Message
 Post subject: Recommended way to create a multi-item multi-table summary
PostPosted: Wed May 21, 2008 8:42 am 
Newbie

Joined: Tue May 16, 2006 5:48 pm
Posts: 6
I often need to display a read-only list of sumary data for multiple entries on the screen to allow a user to pick one item to edit e.g. show summary data for all customers or all orders.

In the past I have modelled these as persistent objects and allowed Hibernate to fetch all rows eagerly normally using inner joins. However this results in a large amount of redundant data being loaded and sometimes many queries.

Before using Hibernate I would have created a custom view and some simple sql which joined the tables and returned the few columns required.

Is there a standard approach to use Hibernate to return the sort of summary data required for the read-only lists described above?

Many thanks

Martin


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 9:01 am 
Newbie

Joined: Wed May 21, 2008 8:33 am
Posts: 5
Hi,
You have not mentioned any details of the problem. I suppose it is about querying only a few of the columns from a table plus being able to join 2 or more tables and fetching only the required columns.

I think you can create a custom query that returns set of columns from multiple tables. Check the manual Chapters 14, 16.

regards
Virimchi


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 9:24 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I would say that a standard approach would be to do lazy loading of your objects, and implement the open session in view pattern. This will provide your applications with the data they need, but minimize queries to the database that are being used to load data that is not needed by the client.

Here's more information on the Open Session in View Design Principle.

http://www.hibernate.org/43.html

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 2:03 pm 
Newbie

Joined: Tue May 16, 2006 5:48 pm
Posts: 6
The custom query looks like the only way to achieve the performance gains.

Is it possible to make Hibernate populate custom pojos with the results from a custom query which accesses multiple tables

E.g. Can I make Hibernate return a list of UserSummary objects
custom query: select ... from user, address, order where ...;

Custom Pojo:
public class UserSummary {
String surname;
String city;
int numberOfOrders;
}

Thanks

Martin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.