-->
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.  [ 2 posts ] 
Author Message
 Post subject: Can someone help with this association?
PostPosted: Thu Feb 25, 2010 1:01 pm 
Newbie

Joined: Tue Jan 24, 2006 12:40 pm
Posts: 7
It's been about 4 years since I've done anything with Hibernate, so I'm very rusty. I have the following schema as an example:

create table employee
(
id integer primary key auto_increment,
name varchar(64) not null,
job_title integer not null
);

create table job_title
(
id integer primary key auto_increment,
name varchar(64)
);

create table employee_job_title
(
id integer primary key auto_increment,
title_id integer not null,
employee_id integer not null
);

alter table employee_job_title add foreign key(title_id) references job_title(id);
alter table employee_job_title add foreign key(employee_id) references employee(id);

Assuming I have a class "Employee" with a method like setJobTitle(JobTitle title), how would I set up the mappings for Employee and JobTitle so that it would link them through the employee_job_title table?


Top
 Profile  
 
 Post subject: Re: Can someone help with this association?
PostPosted: Fri Feb 26, 2010 3:12 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
You can define it using @ManyToMany
Please read the tutorial http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/


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

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.