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...
Regards, Dave Brown
SCJP 6 - [url]http://www.dbws.net/[/url] - Check out Grails Forum
Joined: Aug 24, 2005
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 ]