• 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 Bags & Composite IDs

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am new to Hibernate and trying to convert my existing web application's data layer to using it.
One of the problems I've run into is the following:
I have a Portal class, that has an Id, Name, URL, etc as properties. It's mapped to a portal table.
In the database I have another table that maintains a mapping of portal_ids to zipcodes.
So the table has the following structure:


where (portal_id, zipcode) makes up the primary key.


What I'm trying to achieve is to load the list of zipcodes a portal covers everytime I load a portal object in my application.

So I have a List object within my Portal class that will contain the list of zipcodes (string objects).

Here are my questions:
1) Should I represent the portal-2-zipcode mapping table as a java object?
2) Or is there another method of loading the zipcode information when I have a portal loaded?
3) In case the portal-2-zipcode is a class, what's the best approach to represent the composite id?
4) Should I use bag or map?

This is only a read-only operation. I don't need to add/remove any zipcodes after the portal object is loaded.

Thanks in advance for all your help.

Cagan
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This is only a read-only operation


Here's your way out - since it is a read only operation you can use a view, and map the view rather than the more complex table structure as it stands, particularly since composite ids are a little awkward in Hibernate.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic