我有两个带有复合主键的表,我希望使用jpa

时间:2017-07-23 16:37:07

标签: java mysql spring jpa

数据库表详情:

EmployeeDetail:

  • PK由employeeIdteam组成,其他列为lnamefname

EmployeePerformance:

  • PK由employeeIdemployeeIdmonth组成,其他列为grade

我应该如何编写上表详细信息的实体类(持久性)?

我有两个具有嵌入式ID

的持久化类
@Entity
public class EmployeePerformance  {

  @EmbeddedId
  private EmployeePerformancePK emplPerfPK;

  private String grade;
}


@Embeddable
public class EmployeePerformancePK   {

  private int employeeId;
  private String month;
}


@Entity
public class EmployeeDetail  {

  @EmbeddedId
  private EmployeeDetailPK emplPerfPK;

  private String lname;
  private String fname;

}


@Embeddable
public class EmployeeDetailPK   {

  private int employeeId;
  private String team;

}

使用JPA概念

我想在spring web service

中执行此查询
SELECT 
FROM EmployeeDetail
INNER JOIN EmployeePerformance ON EmployeeDetail.employeeId = EmployeePerformance.employeeId 
WHERE EmployeePerformance.grade = "B";

0 个答案:

没有答案