• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 177
Hibernate Python Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
reply
    Bookmark Topic Watch Topic
  • New Topic