Hi,
I'm totally new to Hibernate and have some trouble creating a many to many association with annotations.
I have two classes User and Department
Code:
@Entity
public class User implements Serializable
{
@ManyToMany(targetEntity =com.test.Department.class)
@JoinTable(
name="JOIN_USER_DEPARTMENT",
joinColumns=@JoinColumn(name="ID_DEPARTMENT")
inverseJoinColumns=@JoinColumn(name="ID_USER"))
private Collection<Departments> departments; // and get/set methods for this
}
Code:
@Entity
public class Department implements Serializable
{
@ManyToMany(targetEntity =com.test.User.class)
@JoinTable(
name="JOIN_USER_DEPARTMENT",mappedBy="departments")
}
The code without the many to many association has been up and running without problems.
As soon as I add the association I get this Exception:
Code:
Could not determine type for: java.util.Collection, at table: User, for columns: [org.hibernate.mapping.Column(departments)]
Im not really wondering about the exception because in general I don't understand how this is supposed to work at all.
My guess is that Hibernate tries to map the department attribute to a column in the User table which - of course - does not exist.
Thanks in advance