查询输出抛出异常

时间:2019-11-16 07:57:13

标签: java hibernate spring-data-jpa

我正在使用休眠数据jpa。这是我的存储库

公共接口MappingRepository         扩展JpaRepository(ConfigMapping,Long){

@Query(value = "select count(machine_id) from machine_configuration where configuration_id =:Id and vm_machine_id =:vMId", nativeQuery = true)
public Long getCount(@Param("Id") Long Id, @Param("vMId") Long vMId);

现在在我的服务类中,当我尝试使用

获得结果时
for (int i = 0; i < vMList.size(); i++) {
     Long vMCount = vMRepo.getCount(Id, vMList.get(i));
   }

所以我总是遇到异常

com.sun.jdi.InvalidTypeException: generated value (java.math.Biginteger) is not compatible with declared type (java.lang.Long)

注意:vMList是VM的列表(长列表)

2 个答案:

答案 0 :(得分:0)

使用原始long(而不是包装对象Long)。 请参阅示例5。派生计数查询 https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.core-concepts

答案 1 :(得分:0)

实际上,我通过将vMlist更改为BigInteger而不是Long解决了该问题。问题是,我希望将vm List设置为Long,而我希望它位于BigInteger。

我还将getCount()方法更改为BigInteger而不是Long。