Hello,
I have two entities assotiated as ManyToMany:
Code:
@Entity
public class Employer implements Serializable {
@ManyToMany(
targetEntity=Department.class,
cascade={CascadeType.PERSIST, CascadeType.MERGE}
)
@JoinTable(
name="EMPLOYER_DEPARTMENT",
joinColumns=@JoinColumn(name="EMPLOYER_ID"),
inverseJoinColumns=@JoinColumn(name="DEPARTMENT_ID")
)
public Collection getDepartments() {
return departments;
}
...
}
Code:
@Entity
public class Department implements Serializable {
@ManyToMany(
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
mappedBy = "departments",
targetEntity = Employer.class
)
public Collection getEmployers() {
return employers;
}
}
I need to write some info about who is the employer in department (one employer can be in different departments with different roles).
So I think to write this info in ref table like this:
EMPLOYER_DEPARTMENT
EMPLOYER_ID | DEPARTMENT_ID | ROLE | DESCRIPTION
Is there possibility to do that without creating entity mapping class for this table? Or may be there are another solutions?