No problem. I have a many to many between student and course like so:
In Course.java
Code:
@Entity
@Table(name = "Course")
@SequenceGenerator(name = "Course_Sequence", allocationSize=1, sequenceName = "course_seq")
public final class Course implements Serializable {
/**
* The list of student's enrolled on the course.
*/
private Set<Student> mEnrolledStudents = new HashSet<Student>();
...........
/**
* Return the students enrolled on the course.
* @return mEnrolledStudents student's
*/
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(name = "course_student",
joinColumns = @JoinColumn(name = "course_id", referencedColumnName = "course_id"),
inverseJoinColumns = @JoinColumn(name = "student_id", referencedColumnName = "student_id"))
public Set<Student> getStudents() {
return mEnrolledStudents;
}
/**
* Set the students enrolled on this course.
* @param pEnrolledStudents students
*/
public void setStudents(final Set<Student> pEnrolledStudents) {
this.mEnrolledStudents = pEnrolledStudents;
}
...........
}
And in Student
Code:
@Entity
@Table(name = "Student")
@SequenceGenerator(name = "Student_Sequence", allocationSize=1, sequenceName = "student_seq")
public final class Student implements Serializable {
/**
* Course student is enrolled on
*/
private Collection<Course> mCourses = new ArrayList<Course>();
.........
/**
* Return the courses the student is enrolled on.
* @return mCourses courses
*/
@ManyToMany(mappedBy = "students", cascade ={CascadeType.PERSIST, CascadeType.MERGE})
public Collection<Course> getCourses() {
return mCourses;
}
/**
* See the course the student is enrolled on
* @param pCoursesEnrolledOn courses
*/
public void setCourses(final Collection<Course> pCourses) {
this.mCourses = pCourses;
}
...........
}
Let me know how you get on
Cheers,
Andy