• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how do I get one to many relation when only one column is there in table if many

 
Vinay Taneja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a very simple basic requirement creating application for taking papers of any domain. In this application, I store questions in questions table and its answers which can be single or multi in answers table.
I have table questions(id,question, ans1,ans2,ans3,ans4) and table answers(question_id,answer_id). Now in answers table there is no primary key, or I can make both the columns as primary key. also in my domain object Question I have a collection of Answers but my problem is because in table answers there are only two columns and in actual I don't need a class to represent this table, should I still create an Entity class for answers. Also what should be the primary key of this table, if we take both columns as the primary key, what should be generation strategy in entity class. Also what will be join condition.
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does your table questions have the columns ans1, ans2, ans3 and ans4 and your table answers just ids... Shouldn't it be like: question(id, question, answers) answer(id,answer) for the fields? Maybe i am wrong and i just dont get your requirement. Feel free to elaborate.
 
Vinay Taneja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how I am planning to put my data
Questions table
-----------
id|question |opt1 |opt2 |opt3 |opt4 |opt5 |marks
1|what are the valid access qualifiers of a class |public |default|private |protected |null |2
2|what are the valid implementations of java.util.Collection|ArrayList|Arrays|Collections|HashSet |Vector|3

Answers table
----------
id|ans
1 |1
1 |2
2 |1
2 |4
2 |5

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic