Thread: Require assistance in Postgres + Hibernate : Error:java.math.BigInteger cannot be cast to java.math.BigDecimal
Require assistance in Postgres + Hibernate : Error:java.math.BigInteger cannot be cast to java.math.BigDecimal
From
Vinodh NV
Date:
Hi,
Require assistance on the below:
Code snippet:
Map<String,Object> ic;
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:
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:
Can u let me know the solution for this?
Regards,
Vinodh
Re: Require assistance in Postgres + Hibernate : Error:java.math.BigInteger cannot be cast to java.math.BigDecimal
From
rob stone
Date:
Hi, On Tue, 2018-02-13 at 14:28 +0530, Vinodh NV wrote: > Hi, > > 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: > > Can u let me know the solution for this? > > Regards, > Vinodh This is not a Postgres question per se. The method is documented as:- public static BigDecimal valueOf(long val) HTH, Rob
Re: Require assistance in Postgres + Hibernate : Error:java.math.BigInteger cannot be cast to java.math.BigDecimal
From
Francisco Olarte
Date:
Vinodh: On Tue, Feb 13, 2018 at 9:58 AM, Vinodh NV <linktovinodh@gmail.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.
Re: Require assistance in Postgres + Hibernate : Error:java.math.BigInteger cannot be cast to java.math.BigDecimal
From
Francisco Olarte
Date:
On Tue, Feb 13, 2018 at 12:39 PM, rob stone <floriparob@gmail.com> wrote: >> long count = ((BigDecimal)ic.get(“EB”)).longValue(); .. > The method is documented as:- > public static BigDecimal valueOf(long val) His problem seems to be the opposit, he does not have the long value and wants it. Francisco Olarte.
Re: Require assistance in Postgres + Hibernate : Error:java.math.BigInteger cannot be cast to java.math.BigDecimal
From
Vinodh NV
Date:
Thanks for the update Francisco. I had one more query:
In Oracle the syntax for calling a stored procedure is Session sess = (Session) entityManager.getDelegate();
sess.createSQLQuery("{ call reset() }").executeUpdate();
Can you please let me know if the below equivalent for postgres is correct?
Session sess = (Session) entityManager.getDelegate();
sess.createSQLQuery("select reset()");
Session sess = (Session) entityManager.getDelegate();
sess.createSQLQuery("select reset()");
Regards,
Vinodh
On Tue, Feb 13, 2018 at 5:12 PM, Francisco Olarte <folarte@peoplecall.com> wrote:
On Tue, Feb 13, 2018 at 12:39 PM, rob stone <floriparob@gmail.com> wrote:
>> long count = ((BigDecimal)ic.get(“EB”)).longValue();
..
> The method is documented as:-
> public static BigDecimal valueOf(long val)
His problem seems to be the opposit, he does not have the long value
and wants it.
Francisco Olarte.
Re: Require assistance in Postgres + Hibernate : Error:java.math.BigInteger cannot be cast to java.math.BigDecimal
From
Francisco Olarte
Date:
Vinodh: You are BOTTOM QUOTING a message which has nothing to thank me from, I was just trying to clarify a misunderstanding of your original question. On Tue, Feb 13, 2018 at 4:14 PM, Vinodh NV <linktovinodh@gmail.com> wrote: > Thanks for the update Francisco. I had one more query: > In Oracle the syntax for calling a stored procedure is > Session sess = (Session) entityManager.getDelegate(); > sess.createSQLQuery("{ call reset() }").executeUpdate(); > > Can you please let me know if the below equivalent for postgres is correct? > Session sess = (Session) entityManager.getDelegate(); > sess.createSQLQuery("select reset()"); Had you quoted the correct message you would have seen I told you I do not know hibernate, so no idea whar a session, entityManaer or or delegates are. I also haven't done anthing serious with Oracle in this century. So, I cannot tell you much. Which I do know is in classic postgres you normally call functions this way, by selecting. Francisco Olarte.