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?