Sql Spring JPA:没有从DB in到DTO的转换器数据

Sql Spring JPA:没有从DB in到DTO的转换器数据,sql,postgresql,spring-boot,jpa,Sql,Postgresql,Spring Boot,Jpa,我的存储库中有一个自定义查询。我创建了一个DTO接口,如下所示: public interface ImagePathAndID { String getImagePath(); Integer getIdProduct(); } 我的问题是: @Query(value = "select image.image_path, product.product_id from image\r\n" + " inner join p

我的存储库中有一个自定义查询。我创建了一个DTO接口,如下所示:

public interface ImagePathAndID {
    String getImagePath();
    Integer getIdProduct();
}
我的问题是:

@Query(value = "select image.image_path, product.product_id from    image\r\n" + 
            "           inner join product  on product.product_id = image.product_id\r\n" + 
            "           inner join category as c on product.category_id = c.category_id \r\n" + 
            "           where c.category_id = :id ", nativeQuery = true)
    public List<ImagePathAndID > selectAllImagePathForCategory(@Param("id") int id);
我得到了
ImagePathAndID
的3个对象,但是这个对象的值是
null
。 输出为:

null,null
null,null
null,null

这里的关键是定义的属性应该与接口方法命名约定完全匹配。提及

您应该修改查询和接口方法,如下所示

查询

@Query(value ="select image.image_path as imagePath, product.product_id as productId from    image\r\n" + 
        "           inner join product  on product.product_id = image.product_id\r\n" + 
        "           inner join category as c on product.category_id = c.category_id \r\n" + 
        "           where c.category_id = :id ", nativeQuery = true)
public List<ImagePathAndID > selectAllImagePathForCategory(@Param("id") int id);

}

这里的关键是定义的属性应该与接口方法命名约定完全匹配。提及

您应该修改查询和接口方法,如下所示

查询

@Query(value ="select image.image_path as imagePath, product.product_id as productId from    image\r\n" + 
        "           inner join product  on product.product_id = image.product_id\r\n" + 
        "           inner join category as c on product.category_id = c.category_id \r\n" + 
        "           where c.category_id = :id ", nativeQuery = true)
public List<ImagePathAndID > selectAllImagePathForCategory(@Param("id") int id);
}

public interface ImagePathAndID {
   String getImagePath();
   Integer getProductId();