日期:2014-05-19  浏览次数:20758 次

懂hibernate hql查询的进来,count查询出来的数据不正确,只有58分了,只求高手来秒杀
员工和部门是多对多关系,一个员工有多个部门
员工和职位是多对多关系,一个员工有多个职位
部门和职位是一对多关系,一个部门下有多个职位

员工表

@Entity
@Table(name = "t_employees")
public class Employees implements Serializable
{
/**

*/
private static final long serialVersionUID = -3878808306609451005L;
private Long id;
private String employeesName;
  private Set<EmployeesLeave> employeesLeave = new HashSet<EmployeesLeave>();
private Set<Departments> departmentses = new HashSet<Departments>();
private Set<EmployeesPosition> employeesPositions = new HashSet<EmployeesPosition>();
private Set<RemunerationNotice> remunerationNotices = new HashSet<RemunerationNotice>();
private BranchCompanyData branchCompanyData;
   

  .....


  @OneToMany(mappedBy = "employees", fetch = FetchType.EAGER)
public Set<EmployeesLeave> getEmployeesLeave()
{
return employeesLeave;
}

@ManyToMany(targetEntity = Departments.class, cascade =
{ CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER)
@JoinTable(name = "T_Employees_Departments", joinColumns = @JoinColumn(name = "employeesId"), inverseJoinColumns = @JoinColumn(name = "departmentsId"))
public Set<Departments> getDepartmentses()
{
return departmentses;
}

@ManyToMany(targetEntity = EmployeesPosition.class, cascade =
{ CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER)
@JoinTable(name = "T_Employees_EmployeesPosition", joinColumns = @JoinColumn(name = "employeesId"), inverseJoinColumns = @JoinColumn(name = "employeesPositionsId"))
public Set<EmployeesPosition> getEmployeesPositions()
{
return employeesPositions;
}

@OneToMany(mappedBy = "employees", fetch = FetchType.EAGER)
public Set<RemunerationNotice> getRemunerationNotices()
{
return remunerationNotices;
}

@ManyToOne
public BranchCompanyData getBranchCompanyData()
{
return branchCompanyData;
}

@OneToMany(mappedBy = "employees", fetch = FetchType.LAZY)
public Set<ClockIn> getClockIn()
{
return clockIn;
}

}


职位表
@Entity
@Table(name = "t_employeesPosition")
public class EmployeesPosition
{
private Long id;
private String positionName;
private String positionForMoreInformation;

private Set<Employees> employeeses = new HashSet<Employees>();
private Departments departments;
   
@Id
@GeneratedValue
public Long getId()
{
return id;
}

@Column(length = 88)
@ManyToMany(targetEntity = Employees.class, cascade =
{ CascadeType.PERSIST, CascadeType.MERGE }, mappedBy = "employeesPositions")
public Set<Employees> getEmployeeses()
{
return employeeses;
}
   
@ManyToOne
public Departments getDepartments()
{
return departments;
}
  ......



部门表
@Entity
@Table(name = "t_departments")
public class Departments
{
private Long id;
private String departmentsName;
private String departmentsForMoreInformation;
private Set<Employees> employeeses = new HashSet<Employees>();

private Set<EmployeesPosition> employeesPositions = new HashSet<EmployeesPosition>();

  @Id
@GeneratedValue
public Long getId()
{
ret