@ManyToMany Duplicate Entry Exception
Posted
by
zp26
on Stack Overflow
See other posts from Stack Overflow
or by zp26
Published on 2011-01-14T13:37:22Z
Indexed on
2011/01/14
13:54 UTC
Read the original article
Hit count: 212
I have mapped a bidirectional many-to-many exception between the entities Course and Trainee in the following manner:
Course
{
...
private Collection<Trainee> students;
...
@ManyToMany(targetEntity = lesson.domain.Trainee.class,
cascade = {CascadeType.All}, fetch = {FetchType.EAGER})
@Jointable(name="COURSE_TRAINEE",
joincolumns = @JoinColumn(name="COURSE_ID"),
inverseJoinColumns = @JoinColumn(name = "TRAINEE_ID"))
@CollectionOfElements
public Collection<Trainee> getStudents() {
return students;
}
...
}
Trainee
{
...
private Collection<Course> authCourses;
...
@ManyToMany(cascade = {CascadeType.All}, fetch = {FetchType.EAGER},
mappedBy = "students", targetEntity = lesson.domain.Course.class)
@CollectionOfElements
public Collection<Course> getAuthCourses() {
return authCourses;
}
...
}
Instead of creating a table where the Primary Key is made of the two foreign keys (imported from the table of the related two entities), the system generates the table "COURSE_TRAINEE" with the following schema:
I am working on MySQL 5.1 and my App. Server is JBoss 5.1. Does anyone guess why?
© Stack Overflow or respective owner