Re: Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: Vinodh NV <linktovinodh(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal
Date: 2018-02-13 11:41:04
Message-ID: CA+bJJbzxY_BPqw_JD1cb+DEJhL2O8XEyBs0Z_M7668cFCJ3gHg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Vinodh:

On Tue, Feb 13, 2018 at 9:58 AM, Vinodh NV <linktovinodh(at)gmail(dot)com> wrote:
> Require assistance on the below:
> Code snippet:
> Map<String,Object> ic;
> //Populate values for ic
> long count = ((BigDecimal)ic.get(“EB”)).longValue();
>
>
> Getting the below error:
> java.math.BigInteger cannot be cast to java.math.BigDecimal
> ®java.lang.ClassCastException: java.math.BigInteger cannot be cast to
> java.math.BigDecimal
>
> Since this is not part of a query doing select cast (EB as bigint) will not
> help in this case:

I do not know hibernate, so Ihaven't the sligstest idea of why
get("EB") returns BigInteger or why you do not cast it to BigInteger
instead of BigDecimal.

But if your problem is it sometimes has Bigdecimal and sometimes
BigInteger you could try casting it to the parent, Number, which is
the one specifying longValue() and would make the code work with both.

Francisco Olarte.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Olarte 2018-02-13 11:42:44 Re: Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal
Previous Message rob stone 2018-02-13 11:39:36 Re: Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal