0

I have a problem with Hibernate. I have three tables jobs, actions and mails. For jobs and actions there is a many-to-many relationship. So I created a join-table Action_Jobs which contains the ids of both tables.

Now, how can I build a relationship from the join-table Action_Jobs to my third table mails? Because from the combination of jobs and actions my mails are identified.

Kay
  • 12,918
  • 4
  • 55
  • 77
rawshell
  • 3
  • 3

2 Answers2

0

Create a new table Action_Jobs which maps Jobs to Action. Use the primary key of Action_Jobs table and map with Mails table. The primary key can be an auto increment column.

Hope this helps...

Atropo
  • 12,231
  • 6
  • 49
  • 62
Renjith
  • 3,274
  • 19
  • 39
  • Thanks 4 answer but I dont get it. How I map Jobs to Action in another table? – rawshell Dec 18 '12 at 09:55
  • My assumption is corresponding to each job, there will be an action.Table structure will be like Action_Jobs_Key(autoincrement),jobs_id(Pk of JOBS),action_id(PK of Actions). – Renjith Dec 18 '12 at 10:01
  • Created an entity Jobs_Action and mapped action and job with @JoinColumn to it. Seems to work – rawshell Dec 18 '12 at 12:47
0

You cannot join Action_Jobs table with other table because it is not Entity. According to your question, jobs, actions and mails are entities.Action_Jobs table is used to join actions and jobs table and not entity. So you should join mails table with jobs and actions tables directly.

Sai Ye Yan Naing Aye
  • 6,622
  • 12
  • 47
  • 65