I want to define two tables
create table cars (
id integer primary key,
name varchar
);
create table car_model (
car_id integer references cars(id),
model_type varchar not null,
model_attr1 varchar,
model_attr2 varchar,
primary key (car_id, model_type)
);
I need to do the following in Hibernate
1. Create two classes: Cars and CarModel
2. Define the primary key for CarModel as a composite key comprising of the foreign key "car_id" and the column "model_type"
3. Define a OneToMany mapping from Cars to CarModel and a ManyToOne mapping from CarModel to Cars. And be able to retrieve Cars from Car_Model and Car_Model from Cars.
How do I relect such a relationship using Hibernate annotations?
Thanks in advance
Abhishek Verma
|