I have two tables as mentioned below. The point is to have 'n' choice for my question. I have designed to have composite key on the second table instead of having one more column for primary key. With this approach i have two questions.
Is this a good approach in table design? i mean TABLE QUESTIONCHOICE has composite key rather than a primary key.
How do i make one to many mapping in Hibernate between QUESTIONBANK and QUESTIONCHOICE tables using annotations?
Any points and suggestions will be of great help.
Thanks,
-Vijay Selvaraj
CREATE TABLE QUESTIONBANK(
QUESTIONID INT NOT NULL AUTO_INCREMENT(10001, 1),
QUESTION VARCHAR(200) NOT NULL,
TOPIC VARCHAR(20) NOT NULL,
SUBTOPIC VARCHAR(20) NOT NULL,
COMPLEXITY SMALLINT NOT NULL DEFAULT 1,
QUESTIONTYPE SMALLINT NOT NULL,
VERSION INT NOT NULL DEFAULT 0,
CONSTRAINT QUESTIONBANK_PK PRIMARY KEY (QUESTIONID)
);
CREATE TABLE QUESTIONCHOICE(
QID INT NOT NULL,
CHOICE VARCHAR(100) NOT NULL,
CORRECT_CHOICE BOOLEAN,
VERSION INT NOT NULL DEFAULT 0,
CONSTRAINT QUESTIONCHOICE_PK PRIMARY KEY (QID, Choice),
CONSTRAINT QUESTIONCHOICE_FK FOREIGN KEY (QID) REFERENCES QUESTIONBANK (QUESTIONID)
);