弹簧数据JPA:未找到能够从类型转换的转换器

时间:2018-10-20 08:50:11

标签: spring-data-jpa jpql

我正在使用Spring Data JPA。我正在尝试使用EmployeeRoom Employee MappingInner 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]",

1 个答案:

答案 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类的完全限定路径,并且具有与传递的属性匹配的构造函数。