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

时间:2019-04-03 11:55:10

标签: java postgresql spring-data-jpa stored-functions

我在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结果

enter image description here

1 个答案:

答案 0 :(得分: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;
}

}

希望这会有所帮助。