我想知道如何使用 JPA 映射以下要求
我有一个具有以下属性的项目实体
projectNo (auto generated)
projectRequestedBy
approvedBy
员工实体
employeeNumber (primary key)
employeeName
employeeTitle
employeePhone
我想知道如何有效地映射employeeNumber
项目实体中的 projectRequestedBy 和approvedBy 属性?
而且我还想知道当我对实体类执行查询时如何显示和employeeName
属性?理想情况下,如果我尝试获取项目记录,我希望拥有以下记录employeeTitle
employeePhone
Project
projectNo projectRequestedByName projectRequestedByTitle approvedByName approvedByTitle
任何帮助都是非常可观的。
更新 1
项目实体
@Entity
@Table(name = "PROJECT")
public class Project
private Long projectNo;
@ManyToOne
@JoinColumn(name="EMP_NUMBER", insertable =false, updatable=false)
private Employees employees;
员工实体
@Entity
@Table(name = "EMPLOYEES")
public class Employees {
@OneToMany
@JoinColumn(name="EMP_NUMBER", nullable = false)
private Collection<Project> project;