[英]How to work around java.math.BigInteger cannot be cast to java.lang.Integer?
I have a problem with Spring-boot, my request repository is written like that:我对 Spring-boot 有疑问,我的请求存储库是这样写的:
package com.ftm.webappli.repository.population;
import java.util.List;
import com.ftm.webappli.model.population.All;
import com.ftm.webappli.model.population.MenWomen;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
public interface AllRepository extends JpaRepository<All, Long> {
@Query(
value = "SELECT SUM(p15_pop) AS total_population, SUM(p15_poph) AS total_hommes, SUM(p15_popf) AS total_femmes FROM public.iris_pop_2015 WHERE com = :code",
nativeQuery = true)
List<MenWomen> sumPopulationHommeFemme(String code);
}
She return 3 BigInt on PostgreSQL.她在 PostgreSQL 上返回 3 BigInt。
In the method i've write:在我写的方法中:
package com.ftm.webappli.model.population;
import java.io.Serializable;
import java.math.BigInteger;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.FieldDefaults;
@Entity
@FieldDefaults(level = AccessLevel.PRIVATE)
@Getter
@NoArgsConstructor
@Setter
@Table(schema = "public", name = "iris_pop_2015")
public class MenWomen implements Serializable {
@Id
@Column(name = "total_population")
private BigInteger nbTotal;
@Column(name = "total_hommes")
private BigInteger nbMen;
@Column(name = "total_femmes")
private BigInteger nbWomen;
}
But i'v an error:但我有一个错误:
Failed to convert from type [java.lang.Object[]] to type [com.ftm.webappli.model.population.MenWomen] for value '{5766, 2767, 2999}';无法将类型 [java.lang.Object[]] 转换为类型 [com.ftm.webappli.model.population.MenWomen] 的值“{5766, 2767, 2999}”; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type
嵌套异常是 org.springframework.core.convert.ConverterNotFoundException: 没有找到能够从类型转换的转换器
I've try to correct my request:我试图纠正我的要求:
"SELECT SUM(p15_pop)::integer AS total_population, SUM(p15_poph)::integer AS total_hommes, SUM(p15_popf)::integer AS total_femmes FROM public.iris_pop_2015 WHERE com = :code"
And the Model to Integer, ex: Model 到 Integer,例如:
@Column(name = "total_hommes")
private Integer nbMen;
But doesn't work... The request work on PostgreSQL but not on Spring whith the '::integer'但不起作用......该请求适用于 PostgreSQL 但不适用于带有“::integer”的 Spring
I've trys also to correct my java.lang:我也尝试纠正我的 java.lang:
@Repository
public interface AllRepository extends JpaRepository<All, Integer>
Or或者
@Repository
public interface AllRepository extends JpaRepository<All, Long>
Or或者
@Repository
public interface AllRepository extends JpaRepository<All, BigInteger>
But doesn't work... You have an idea?但不起作用......你有想法吗?
Please replace All
with entity name ie, MenWomen
something like below,请将
All
替换为实体名称,即MenWomen
,如下所示,
@Repository
public interface AllRepository extends JpaRepository<MenWomen, Integer>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.