Spring boot 从一个表获取数据并插入另一个表JPA

Spring boot 从一个表获取数据并插入另一个表JPA,spring-boot,hibernate,jpa,spring-data-jpa,nhibernate-mapping,Spring Boot,Hibernate,Jpa,Spring Data Jpa,Nhibernate Mapping,我是JPA的初学者。根据要求,我正在尝试从多个表(emp_登机_详情、美国运通_emp_详情、emp_登机_详情)中获取数据,并插入另一个表,即emp_登机_历史 1。EmpboadingHistoryRepository.java: public interface EmpBoardingHistoryRepository extends JpaRepository<EmpBoardingHistory, Long> { @Query(nativeQuery = true, va

我是JPA的初学者。根据要求,我正在尝试从多个表(emp_登机_详情、美国运通_emp_详情、emp_登机_详情)中获取数据,并插入另一个表,即emp_登机_历史

1。EmpboadingHistoryRepository.java:

public interface EmpBoardingHistoryRepository extends JpaRepository<EmpBoardingHistory, Long> {

@Query(nativeQuery = true, value = "SELECT new com.boarding.boardinghistory.resource.EmpBoardingHistory**(ebd.exemption_type_txt, ebd.exemption_remarks_txt, ebd.emp_no_int, ebd.first_name_txt, ebd.middle_name_txt, ebd.last_name_txt, ebd.email_id_txt, ebd.emp_or_contractor_ind, ebd.vendor_laptop_desktop_asset_txt, ebd.country_origin_txt, ebd.status_txt, aed.billing_po_no_txt, aed.contractor_id_txt, aed.contract_type_txt, aed.proj_master_cd_txt, aed.amex_email_id_txt, aed.amex_laptop_desktop_asset_id_txt, aed.ads_id_txt, aed.cost_center_txt, aed.contractor_id_creation_date, aed.first_billing_date, aed.clarity_resource_role_txt, aed.platform_id_txt, aed.premium_technology_txt, aed.resource_status_txt, aed.onboard_completion_date, eod.resource_leaving_date, eod.departure_date) FROM emp_boarding_details ebd, amex_emp_details aed, emp_offboarding_details eod WHERE ebd.emp_no_int = aed.emp_no_int AND aed.emp_no_int = eod.emp_no_int AND ebd.emp_no_int = :empNo")
    List<EmpBoardingHistory> getEmpBoardingDetails(@Param("empNo") long empNo); 
}
当我尝试调用此GetEmpboadingDetails()时,出现以下异常:

020-06-03 16:24:15.146 DEBUG 68096 --- [nio-8080-exec-5] org.hibernate.SQL                        : SELECT new com.boarding.boardinghistory.resource.EmpBoardingHistory(ebd.exemption_type_txt, ebd.exemption_remarks_txt, ebd.emp_no_int, ebd.first_name_txt, ebd.middle_name_txt, ebd.last_name_txt, ebd.email_id_txt, ebd.emp_or_contractor_ind, ebd.vendor_laptop_desktop_asset_txt, ebd.country_origin_txt, ebd.status_txt, aed.billing_po_no_txt, aed.contractor_id_txt, aed.contract_type_txt, aed.proj_master_cd_txt, aed.amex_email_id_txt, aed.amex_laptop_desktop_asset_id_txt, aed.ads_id_txt, aed.cost_center_txt, aed.contractor_id_creation_date, aed.first_billing_date, aed.clarity_resource_role_txt, aed.platform_id_txt, aed.premium_technology_txt, aed.resource_status_txt, aed.onboard_completion_date, eod.resource_leaving_date, eod.departure_date) FROM emp_boarding_details ebd, amex_emp_details aed, emp_offboarding_details eod WHERE ebd.emp_no_int = aed.emp_no_int AND aed.emp_no_int = eod.emp_no_int AND ebd.emp_no_int = ?
2020-06-03 16:24:15.149 TRACE 68096 --- [nio-8080-exec-5] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [BIGINT] - [909089]
2020-06-03 16:24:15.282  WARN 68096 --- [nio-8080-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1064, SQLState: 42000
2020-06-03 16:24:15.282 ERROR 68096 --- [nio-8080-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper   : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.boarding.boardinghistory.resource.EmpBoardingHistory(ebd.exemption_type_txt, eb' at line 1
继续上面的问题->现在我能够成功地从多个表中检索数据(感谢Jens!),但当我试图将该响应保存到另一个表(即emp_历史记录)中时,数据不会持久化

//检索并保存逻辑

public EmpBoardingHistory selectSaveEmpBoardingHistory(Integer empNo) { 
    //Retrieve Data FROM ONE TABLE 
    List<EmpBoardingHistory> empBoardingHistoryList = empBoardingHistoryRepository.findBoardingHistoryEmpNo(empNo); 
    EmpBoardingHistory empBoardingHistory = new EmpBoardingHistory(); 
    for (EmpBoardingHistory empBoardingHistoryObj : empBoardingHistoryList) 
    { 
    //SAVING DATA INTO ANOTHER TABLE 
    empBoardingHistoryRepository.save(empBoardingHistoryObj);
    empBoardingHistory = empBoardingHistoryObj; 
    } 
    return empBoardingHistory; 
    }
public empboadingshistory选择Saveempboadingshistory(整数empNo){
//从一个表中检索数据
List EmpboadingHistoryList=EmpboadingHistoryRepository.findBoardingHistoryEmpNo(empNo);
empboadingHistory empboadingHistory=新empboadingHistory();
for(empboadingHistory empboadingHistoryOBJ:empboadingHistoryList)
{ 
//将数据保存到另一个表中
empboadinghistoryrepository.save(empboadinghistoryobj);
empboadinghistory=empboadinghistoryobj;
} 
回归历史;
}

您正在查询中使用构造函数表达式:

new com.boarding.boardinghistory.resource.EmpBoardingHistory**(...
这是一个来自JPQL的构造。 但您也将其标记为
nativeQuery=true
,这意味着它被解释为SQL,而SQL没有这样的构造。 使用构造函数表达式或将其标记为本机查询,而不是两者都使用


此外,构造函数表达式包含
**
,这将不起作用。

如果整个目的是将数据从一个表复制到另一个表,我建议使用纯SQL,而不将数据移动到客户端和客户端。很抱歉**是构造函数表达式中的输入错误。谢谢Jens!我已经删除了构造函数表达式,现在它可以正常工作了。
new com.boarding.boardinghistory.resource.EmpBoardingHistory**(...