Spring JPA :: No converter found capable of converting from type

后端 未结 6 1753
有刺的猬
有刺的猬 2021-02-03 23:59

I am using spring with JPA and trying to execute query using @query with SQL query.and trying to map the result to an object. I have different entity class and mapping to other

6条回答
  •  我在风中等你
    2021-02-04 00:20

    You can solve this issue and achieve the result by using projections by making your DTO an interface with getters for columns returned by the query. That's what I did when I faced the same issue.

    For example in your case change StatsDTO to interface like shown below, make sure to give alias for your columns if you are using '.' operator:

    public interface StatsDTO {
        Integer getUserCount();
        Byte getTypeId();
        Instant getModifiedAt();
    }
    

    Also in your query give alias for your columns like userCount, typeId, modifiedAt respectively so that it is mapped correctly.

提交回复
热议问题