need help
have a simple bidirect. manyTomany - hiberAnnotation,
project *-* employee
the project is the owner-side of this manyTomany-relation,
employee is the inverse-side. From Project-Side is public void setEmployees(Collection<Employee> employees) ok. will update ids to association table project_employee .
But from employee-side setProjects(Collection<Project> projects) {....} can not update values to association-Table
Code:
in Project.java defined:
@ManyToMany(
targetEntity=Employee.class,
cascade={CascadeType.PERSIST, CascadeType.MERGE}
)
// @JoinTable(
// name="project_employee_rel",
// joinColumns={@JoinColumn(name="PROJECT", nullable = false)},
// inverseJoinColumns = {@JoinColumn( name="EMPLOYEE")}
// )
private Collection<Employee> employees = new HashSet<Employee>(0);// * - *
in Employee.java :
@ManyToMany(
cascade={CascadeType.PERSIST, CascadeType.MERGE},
mappedBy="employees",
targetEntity=Project.class
)
private Collection<Project> projects = new HashSet<Project>(0);
in hibernate annotaion tutorials
http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/
found:
A many-to-many association is defined logically using the @ManyToMany annotation. You also have to describe the association table and the join conditions using the @JoinTable annotation. If the association is bidirectional, one side has to be the owner and one side has to be the inverse end (ie. it will be ignored when updating the relationship values in the association table)
there are some ways to update the relationship-values from the employee-side(inverse)? except to rebuild all project-Object from employee and project.setEmployees(employees+newEmployee=this). it will be very ugly.
thanx for tipps.