Hi,
I am a complete Newbie to Hibernate and my problem is the following. I do not know howto correctly map a table whose primary key consists of two columns....The other question is more general. Is it better to generate the DDL for the databases before doing the hibernate-mappings or should one design the database tables on the basis of the hibernate mappings and java-classes???
So here is an example...I have 2 tables and I have also created the 2 corresponding Java- classes...the mapping of the class Question.java is not a problem, but how can I tell Hibernate that class Options.java has a primary key with 2 colums and that there is a relationship between Options and Question (1 Question can have many options...)??? (I have read something about composite id...is this the right thing?? )
Thanks for any help and code examples....Are my class-definitions correct??
create table Question
(
question_id integer not null,
question_text varchar(100) not null,
primary key(question_id)
)
create table Options
(
option_id integer not null,
question_id integer not null,
option_text char(20) not null,
primary key(option_id, question_id), foreign key(question_id) references Question(question_id)
)
/***********/
I modelled the corresponding classes like this....is this correct??
public class Question
{
public int question_id;
public String question_text;
//getter and setter....
}
public class Options
{
public int question_id;
public int option_id;
public String option_text;
}
|