-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Mapping a Set inside of a Map
PostPosted: Tue Mar 13, 2007 3:29 pm 
Newbie

Joined: Tue Jan 09, 2007 7:02 pm
Posts: 4
I couldn't find a good example of the kind of association mapping that I want to do, and my paltry understanding of Hibernate mapping is not sufficient for it.

I want to store a Set of objects as the "value" in a Map, so that each entry in the Map is a Set. I know how to map a Map that just has a single object as the "value", and I know how to map a Set, but I don't know how to map a Map of Sets.

My entities are a Respondent, a Question, and a Response (like in a survey). Some Questions are "multi-select", so there can be more than one Response to a given Question for the same Respondent. So I want to set up a Map inside the Respondent object, with the key being the Question (or Question ID), and the value being the set of Response objects for that Respondent and Question.

I have a Respondent table, a Question table, and a Response table. The first two can be thought of as just ID-name entities. The Response table has a foreign key to the Respondent and the Question, and then an integer representing the response itself. Again, the reason I want to use a Set inside a Map is that there can be more than one Response for a given Question and Respondent.

I could create an intermediate entity, like ResponseSet, that would have a single row for a given Respondent and Question, and then this would contain the Responses as a one-to-many relationship. I don't mind creating an extra Java class to model it this way, but I don't like the idea of adding another table for this relationship.

Any help would be appreciated, and also a pointer to where I might have looked to discover the answer to this on my own (e.g. lots of complex mapping examples). I looked around on the hibernate site and blogs but didn't discover anything quite like what I need.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 2:54 am 
Newbie

Joined: Wed Mar 07, 2007 3:26 am
Posts: 16
Location: Hyderabad,India
hi.

if u create data base tables properly with correct primary and foreign key relations ships the hibernate tool will automatically generate the association mappings u no need to map any thing

_________________
sam


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 11:39 am 
Newbie

Joined: Tue Jan 09, 2007 7:02 pm
Posts: 4
I'm happy with my database design and foreign keys. Which "hibernate tool" are you referring to? In general I prefer to make my mapping files by hand so that I know exactly what's going on.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.