我有两个由id_employee关联的表。
--------------------------- --------------------------- table employee table timesheet --------------------------- --------------------------- id_employee id_time name_employee date_entry --------------------------- quant_hour id_employee ---------------------------
我需要做一个select,它返回表employee表中的所有记录和现有相关表时间表中的小时数。有些员工没有在时间表中记录小时数,但应该出现在列表中,因为它们已在员工表中注册。
JPQL对此进行了什么查询?
班级员工
@Entity
public class Employee {
@Id @GeneratedValue
private Long id_employee;
private String name_employee ;
//GETS and SETS
}
课程时间表
@Entity
public class Timesheet {
@Id @GeneratedValue
private Long id_time;
private Double quant_hour;
private Date date_entry;
@ManyToOne
private Employee employee;
//GETS and SETS
}
答案 0 :(得分:0)
如果两个表都正确映射,那么Employee实体将具有Timesheet实体类型的属性(或集合),因此,您只需要获取员工列表:
SELECT e FROM Employee e
当您想要从Employee实体读取时,JPA会自动检索Timesheet(或Timesheets列表)。