在Spring JPA中将存储过程结果集映射到不同/嵌入式Java POJO

时间:2018-07-12 15:45:05

标签: java spring spring-boot jpa spring-data-jpa

我想了解是否可以直接将存储过程结果集直接映射到嵌套的Java POJO。

我具有以下POJO结构:

var links=[{source:"A", target:"B"}, {source:"B", target:"C"}, {source:"D", target:"E"}, {source:"E", target:"C"}];

var nodes=[];

links.forEach(function(link){
    link.source = nodes[link.source] || (nodes[link.source]={eid:link.source});
    link.target = nodes[link.target] || (nodes[link.target]={eid:link.target});
});

存储过程中的查询就像这样,它会导致多人数据:

public class Person {
     private PersonInformation pInfo;
     private PersonContactInformation pContactInfo;
     //getters and setters..

}

public class PersonInformation {
   private String firstName;
   private String lastName;
   //getters and setters...
}

public class PersonContactInformation {
  private String contactNumber;
  private String email;
  //getters and setters
}

所以,我像这样从Spring JPA调用存储过程:

 select p.fName as firstName, p.lName as lastName, p.cNumber as contactNumber, p.email as email from person p where p.id in (1,2,3,4,5);

我想知道如何直接填充所有POJO?例如,

StoredProcedureQuery uspGetEnrichmentPersonInfo = entityManager.createStoredProcedureQuery("Get_Person_Info");

List<Object[]> resultList = uspGetEnrichmentPersonInfo.getResultList();

0 个答案:

没有答案