This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes hibernate & large sets of data.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate & large sets of data.." Watch "hibernate & large sets of data.." New topic
Author

hibernate & large sets of data..

Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Hi All,

so far using hibernate i've been using minimal sets of data, retrieving a users login info, application settings, simple querys etc, but now i've come up against a bit of a stump..

I have a table of contacts around 15000 records, there is a column called ContactType which can be values like "General","Friend","Employer","Employee" etc.. just describing the actual type of contact.

I'm using swing and intend to have two Jtables, one listing the different ContactsTypes, and the second listing the contacts of that particular type.

Before using hibernate I would use JDBC and do a "select distinct (ContactType) from contacts" to retrieve the different contacttypes used to populate the type table but using hibernate I'm not sure how to do this, I have a hibernate mapped contact bean but it seems like massive overhead to use hibernate to do the simple SQL equivalent as above..

And secondly I wanted to ask about hibernates paging.. I understand it works on persisted collections only, So i would have to retrieve all 15000 contacts regardless. Is this true ? Again this seems like an awful approach if I only want to display say 20 records to the user...

Thanks Dave...


Regards, Dave Brown
SCJP 6 - [url]http://www.dbws.net/[/url] - Check out Grails Forum
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
select distinct (ContactType) from contacts


Take a look at the Projections.distinct() method in the Hibernate API. It will allow you to do a select distinct() query.

But that sounds pretty inefficient if you have more than a few rows in your table. I would suggest creating a second table with a unique set of contact type values. As an added bonus, you can setup referential integrity between the two tables to ensure only valid contact types are in the contacts table.

I wanted to ask about hibernates paging


Hibernate has methods to help with paging. You can call the setFirstResult() and setMaxResults() methods of the Query or Criteria classes to limit the data returned from the query.
[ March 03, 2006: Message edited by: Scott Johnson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate & large sets of data..