我在 JPA 中有两个表(模型),如下所示:
Table Employee| | Table Person |
--------------| ----------------
id | | id |
mobile_number | | employee_id |
| address |
我有手机号码,我需要知道地址吗?如何使用 JPA 来做到这一点?
由于我使用的是 JPA,我还需要编写一个查询来连接这两个表,然后返回结果吗?(就像对单个表进行操作时,JPA 为您提供 getByid() 或 getBymobileNumber 等函数)
实体bean:
@Entity
@Table(name = "employee")
public class Employee {
@CreatedDate
@Temporal(TemporalType.DATE)
private Date created;
@LastModifiedDate
@Temporal(TemporalType.DATE)
private Date lastModified;
private String mobileNumber;
}
@Entity
@Table(name = "Person")
public class Person {
@CreatedDate
@Temporal(TemporalType.DATE)
private Date created;
@LastModifiedDate
@Temporal(TemporalType.DATE)
private Date lastModified;
@OneToOne
private Employee employee;
}