-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: composite primary keys having a forgeing key
PostPosted: Wed Sep 06, 2006 6:54 am 
Newbie

Joined: Fri Aug 18, 2006 9:11 am
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.