我有两个名为EmployeeEntity
和EmployeeDeparmentEntity
的实体。如果我获取该员工,我想要获取所有活跃的部门。我已经为这两个实体使用了双向映射。
EmployeeDeparment
@Entity
public class EmployeeDeparment implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
@JoinColumn(name = "employeeid")
private EmployeeEntity employeeentity;
@Temporal(javax.persistence.TemporalType.DATE)
private Date addeddate;
@Temporal(javax.persistence.TemporalType.DATE)
private Date modifieddate;
@ManyToOne
private EmployeeEntity reportingTo;
@ManyToOne
private DepartmentMaster departmentID;
private boolean status;
}
答案 0 :(得分:0)
根据您的情况,我提出了以下标准的hibernate查询,这可能对您的情况有所帮助。
Criteria criteria = session.createCriteria(EmployeeDeparment.class);
criteria.add(Expression.eq("status",true)); //all active department
criteria.add(Expression.eq("employeeentity.id",1234)); //set the employee id
List lisObj = criteria.list();
Iterator it=lisObj .iterator();
while(it.hasNext())
{
EmployeeDeparment p=(EmployeeDeparment)it.next();
p.get(.........);
p.get(.........);
p.get(.........);
}
如果您有任何进一步的问题,请告诉我......