• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hibernate & large sets of data..

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic