我有下面的查询,我想用它为从查询中检索的列创建一个实体类。
select e.emp_id,
c.company_code,
mg.emp_id as mangaer_code
from employee e
left join company c on e.emp_id = c.emp_id
left join manager mg on e.emp_id = c.emp_id = mg.emp_id
如何从这些列创建实体类,需要哪些变量才能在实体类中引用这些列?
View是一个基于SQL语句或函数的结果集的虚拟表,JPA将其视为常规表。创建一个实体并使用JPA注释,如下所示
@Entity
@Immutable
@Table(name = "employee_view")
public class EmployeeView{
//define the required columns from view here
}
有关更多详细信息,请参阅我找到的这篇文章https://medium.com/@jonathan.turnock/exposing-subset-view-of-the-database-带jpa-repository-over-rest-5b9d6e07344b