简体   繁体   English

如何解决 java.math.BigInteger 无法转换为 java.lang.Integer?

[英]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.

相关问题 如何解决 java.math.BigInteger 无法转换为 java.lang.Integer - How to work around java.math.BigInteger cannot be cast to java.lang.Integer java.lang.Integer不能强制转换为java.math.BigInteger - java.lang.Integer cannot be cast to java.math.BigInteger java.math.BigInteger 不能转换为 java.lang.Integer - java.math.BigInteger cannot be cast to java.lang.Integer class java.math.BigInteger cannot be cast to class java.lang.Integer (java.math.BigInteger and java.lang.Integer are in module java.base of load - class java.math.BigInteger cannot be cast to class java.lang.Integer (java.math.BigInteger and java.lang.Integer are in module java.base of load Playorm java.lang.Integer无法强制转换为java.math.BigInteger - Playorm java.lang.Integer cannot be cast to java.math.BigInteger java.math.BigInteger 不能强制转换为 java.lang.Integer,ZAC5C24B64B4BAC83 - java.math.BigInteger cannot be cast to java.lang.Integer , sql Dialect is not configured java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.math.BigInteger HTTP状态500 - java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigInteger HTTP Status 500 java.math.BigInteger 无法转换为 java.lang.Long - java.math.BigInteger cannot be cast to java.lang.Long java.lang.Long无法强制转换为java.math.BigInteger - java.lang.Long cannot be cast to java.math.BigInteger java.lang.ClassCastException:java.math.BigInteger无法强制转换为java.lang.Long - java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM