Joined: Sun Oct 07, 2012 6:36 am Posts: 3
|
I am dealing with a scenario with a Many-to-Many mapping which is just like the example in Employee to Project through a Join table (ProjectAssociation) with other data in join table. This example is being mentioned so many times. This works fine for me. But I want to retrieve a List of Employees that are allocated to a given Project whom also belong to a given department. The department is a field in the Employee class. When I retrieve the list of Employess, i want them populated with the ProjectAssociations list as well since I can get the project information of employees of that particular department. Following are the entities. They are not complete. I want to just show how my Employee class is.
@Entity public class Employee { private Long Id;
private Department department;
private List<ProjectAssocation> projects; } ------------------------------------------------------------------- private class Department { private Long id;
private String name; } ------------------------------------------------------------------ @Entity @IdClass(ProjectAssociationId.class) public class ProjectAssociation { @Id private Long employeeId;
@Id private Long projectId;
@ManyToOne @PrimaryKeyJoinColumn.... private Employee employee;
@ManyToOne(mappedBy="...") private Project project; } ------------------------------------------------------------------ public class Project { private Long id;
private String projectName;
private List<ProjectAssociation> employees; } ------------------------------------------------------------------ Can someone please tell me the query to get the List of Employees belonging to a specific department (say Engineering) who have been allocated to Project(say Hibernate)
|
|