I am just getting started with Hibernate and I am trying to figure out how to map a relationship I have. I have a class called Section, a class called Question and a class called PossibleAnswer. Section has a list of questions and Question has a list of possible answers. Section and Question have a many-to-many relationship as do Question and PossibleAnswer. I have come up with a schema (and if this is really dumb, please let me know) where there will be a table called Section_Question which will have an id field, a sectionID field, a questionID field and a listPosition field. Additionally, there will be a table called Question_PossibleAnswer which will have an id field, a sectionQuestionID field, a possibleAnswerID field and a listPosition field. (In the actual application, there are five classes that have this relationship, not three).
What I don't understand is how to map these classes. Using the <list> tag, how would one create a primary key field as well as the foreign keys I need?
If someone could point me in the right direction that would be great.
Thanks for your help,
Rob
|