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