Hi,
In our project we use hibernate annotation. Where in we have a requiremet of manytomany relationship . for example , There is employee class with @Entity @Table(name="Employee") public class Employee implements Serializable {
private int empId; private String empName; private List<ProjectVo> projects; @Column(name = "Emp_Name") public String getEmpName() { return empName; }
@Id @Column(name = "Emp_Id") public int getEmpId() { return empId; }
@ManyToMany // (cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable( name="EMP_PROJ", joinColumns={@JoinColumn(name="Emp_Id", referencedColumnName="Emp_Id")}, inverseJoinColumns={@JoinColumn(name="PROJ_ID", referencedColumnName="PROJ_ID")})
public List<ProjectVo> getProjects() { return projects; }
......
}
And a project class , @Entity @Table(name="ProjectVo")
public class ProjectVo implements Serializable { private int projectId; private String projectName; private List<Employee> employee;
@Column(name="Project_Name") public String getProjectName() { return projectName; }
@ManyToMany(mappedBy="projects") public List<Employee> getEmployee() { return employee; } @Id @Column(name="PROJ_ID") public int getProjectId() { return projectId; }
...... }
This will create new table 'EMP_PRJ' with primary keys of 2 tables forming filed in new table (i.e emp_id,project_id).
Our requirement is to add one more column to the 'EMP_PRJ' ,that the mapping table. How we can achieve this .
Thanks in advance pallavi
|