我正在使用Spring Data JPA。我正在尝试使用Employee
从Room Employee Mapping
和Inner Join
表中获取记录。我想显示Employee表中的特定记录,因此在new map
查询中使用了JPQL
。
如果我从查询中删除特定记录,我将获得正确的联接结果,但是当我添加具有特定列的新地图时,我将得到以下错误提示
有人可以告诉我我在做什么错吗?
RoomEmployeeMappingRepository
@Repository
public interface RoomEmployeeMappingRepository extends JpaRepository<RoomEmployeeMapping, Integer>{
@Query("select new map ( emp.sEmpName as sEmpName, emp.sDesignation as sDesignation, "
+ "emp.bIsPaid as bIsPaid , emp.sUnpaidComment as sUnpaidComment) from Employee as emp "
+ "Inner Join RoomEmployeeMapping as roomEmpMapping ON emp.nEmpId=roomEmpMapping.nEmpId "
+ "where roomEmpMapping.nRoomAllocationId=?1 ")
List<Employee> findByNRoomAllocationId(Integer nRoomAllocationId);
}
错误消息
"message": "No converter found capable of converting from type [java.util.HashMap<?, ?>] to type [com.spacestudy.model.Employee]",
答案 0 :(得分:0)
您应该返回Employe实例,如下所示:
select new com.path.to.Employee( emp.sEmpName as sEmpName, emp.sDesignation as sDesignation, "
+ "emp.bIsPaid as bIsPaid , emp.sUnpaidComment as sUnpaidComment)....
确保使用到Employee类的完全限定路径,并且具有与传递的属性匹配的构造函数。