存储功能错误:未找到能够从类型转换的转换器

问题描述 投票:0回答:1

我在PostgreSQL中创建了存储函数。我在PostgreSQL中得到了正确的结果。但是当我尝试使用本机查询调用spring数据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
      ...
}

PostgreSQL结果

enter image description here

java postgresql spring-data-jpa stored-functions
1个回答
0
投票

您可以使用我在我的项目中使用过的可能适用于您的逻辑,也可以不使用。我还没有将它与JPA对象映射一起使用。

public class ObjectSerializer {

private static ObjectMapper objectMapper;

@Autowired
public ObjectSerializer(ObjectMapper objectMapper) {
    ObjectSerializer.objectMapper = objectMapper;
}

public static <T> T getObject(Object obj, Class<T> class1) {
    String jsonObj = "";
    T userDto = null;
    try {
        jsonObj = objectMapper.writeValueAsString(obj);
        userDto = (T) objectMapper.readValue(jsonObj, class1);
        System.out.println(jsonObj);
    } catch (JsonProcessingException jpe) {
    } catch (IOException e) {
        e.printStackTrace();
    }
    return userDto;
}

}

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.