我正在尝试使用nativeQuery根据条件获取行数并将其分配给DTO,但出现以下错误:
Invalid property 'count' of bean class [java.math.BigInteger]: Could not find field for property during fallback access!
下面是DTO:
public interface CountDto {
Integer getCount();
}
下面是查询:
public interface DoctorPracticeUserRepository extends JpaRepository<DoctorPracticeUser, Long> {
@Query(value = "select count(*) as count from orders o inner join treatments t on o.treatment_id = t.id where o.status = 'PAYMENT_APPROVED' and o.product = :product and t.doctor_user_id = :doctorUserId" , nativeQuery = true)
public CountDto getSalesByProdcutForDoctor(@Param("doctorUserId") Long doctorUserId, @Param("product") String product);
}
getSalesByProdcutForDoctor()
执行得很好,但是当我对结果调用getCount()
时,我得到了上面提到的错误。
我尝试将count(*)
强制转换为int
和varchar
,并在DTO中相应地更改类型,但仍然收到类似的错误,只是将BigInteger
更改为{{1} }或Integer
。
还尝试了DTO中的不同类型,例如String
和Long
和BigIntger
,但是仍然发生相同的错误。
我知道我可以通过许多其他方式获得此查询的结果,但是我想知道为什么这行不通。
编辑:堆栈跟踪
BigDecimal