我有一个名为Employee的实体类
@Entity
@Table(name = "employee")
@DynamicUpdate
public class Employee {
private String empId;
private String name;
private String employeeDefaultCountry;
@Id
@Column(name="emp_id", nullable=false, insertable=true, updatable=true, length=8)
public String getEmpId() {
return empId;
}
public void setEmpId(String empId) {
this.empId= empId;
}
...
}
employeeDefaultCountry在其他表“system_defaults”中定义,并且这两个表(employee和system_defaults)之间没有主键和外键关系。 但是,将为system_defaults id(PK)提供一个常量值,该值为常量1.我如何实现它?
通过Native SQL实现:
select empId,name,(select employee_default_country from system_defaults where id=1) as DefaultCountry from employee.
输出:
empId,Name,DefaultCountry
101,Ahmed,India
103,Parkash,India
...
我想在JPA中实现这一点。
注意:此DefaultCountry字段应该是可读的,当保存到DB时,它不应该写。
employee Table fields(emp_id(VARCHAR2),name(VARCHAR2)) only two fields
system_parameters Table fields(id(INT),default_country(VARCHAR2),default_designation(VARCHAR2)) only three fields.
System_defaults的实体:
@Entity
@Table(name = "system_defaults")
@DynamicUpdate
public class SystemDefaults {
Integer id;
String defaultCountry;
@Id
@Column(name = "id", nullable = false, insertable = false, updatable = false)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Basic
@Column(name = "default_country", nullable = false, insertable = false, updatable = false, length = 40)
public String getDefaultCountry() {
return defaultCountry;
}
public void setDefaultCountry(String defaultCountry) {
this.defaultCountry = defaultCountry;
}
}