Get your CodeRanch badge!*
The moose likes Java in General and the fly likes Hibernate Bags & Composite IDs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hibernate Bags & Composite IDs" Watch "Hibernate Bags & Composite IDs" New topic
Author

Hibernate Bags & Composite IDs

Cagan Senturk
Greenhorn

Joined: Jun 14, 2004
Posts: 1
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
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Bags & Composite IDs
 
Similar Threads
Problem in composite key as foreign key mapping w/ hibernate v3.2.6 and jdk-6
How to retrieve detached @ManyToOne entities with relationship
Inverse Question
Not able to view the data persisted in the database.
how to get primary key after doing an insert