【发布时间】:2019-04-03 11:55:09
【问题描述】:
我在 PostgreSQL 中创建了存储函数。我在 PostgreSQL 中得到了正确的结果。但是当我尝试使用本机查询调用 spring data jpa 中的存储函数时。我收到以下错误。
No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.spacestudy.model.ClientRT]"
存储库
@Repository
public interface ClientRoomTypeRepository extends JpaRepository<ClientRoomType, Integer> {
@Query(nativeQuery = true,value = "select * from roomtype(:int_inst_id)")
List<ClientRT> roomtype(@Param("int_inst_id")Integer int_inst_id);
}
结果类 ClientRT
public class ClientRT {
public Integer res_nclient_room_type_id;
public String res_sclient_rt_desc;
public String res_sclient_rt_name;
public String res_sclient_rt_code;
//getter and setter
...
}
PostgrSQL 结果
【问题讨论】:
-
ClientRT 是一个实体吗?
-
不,这不是一个实体。我创造的只是为了回报
-
那么jpa如何将结果映射到那个POJO呢?
-
表示返回类需要作为一个实体。但我在 db 中没有那个表,那么有没有其他方法可以返回它
-
那么你必须实现自己的逻辑来从对象中获取数据并将其设置为 POJO。
标签: java postgresql spring-data-jpa stored-functions