-->
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: Many-to-Many hbm2ddl primary key issue
PostPosted: Tue Aug 30, 2011 6:21 pm 
Newbie

Joined: Tue Jan 04, 2011 7:11 am
Posts: 5
So I have a List that is a unidirectional many-to-many relationship. Here's the code:

Code:
@ManyToMany
@OrderColumn(name="order_num")
@JoinTable(name="TaskgroupToTask",
        joinColumns=@JoinColumn(name="task_id"),
        inverseJoinColumns=@JoinColumn(name="group_id"))
private List<Task> tasks;


I would have thought the primary key on the join table would be a composite key of task_id and group_id, however, instead it is a composite key of task_id and order_num.

This defeats the entire purpose of the join table since this essentially makes the association a many-to-one association, through an irrelevant join table.

If I try to associate 2 tasks with 2 different groups it fails due to the primary key:
Code:
+-----------|--------------|------------------+
| task_id | group_id | order_num |
+-----------|--------------|------------------|
|    1      |       1      |        0        |
|    2      |       1      |        1        |
|    1      |       2      |        0        |   <- Fails since task 1 and order_num 0 already exists--but with many-to-many, I should be able to make this association.
+----------+--------------+----------------+

Where am I doing something wrong?


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.