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.
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.