pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal
6+ messages / 3 participants
[nested] [flat]

* Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal
@ 2018-02-13 08:58  Vinodh NV <linktovinodh@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Vinodh NV @ 2018-02-13 08:58 UTC (permalink / raw)
  To: pgsql-general

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

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal
@ 2018-02-13 11:39  rob stone <floriparob@gmail.com>
  parent: Vinodh NV <linktovinodh@gmail.com>
  1 sibling, 1 reply; 6+ messages in thread

From: rob stone @ 2018-02-13 11:39 UTC (permalink / raw)
  To: Vinodh NV <linktovinodh@gmail.com>; pgsql-general

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




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal
@ 2018-02-13 11:41  Francisco Olarte <folarte@peoplecall.com>
  parent: Vinodh NV <linktovinodh@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Francisco Olarte @ 2018-02-13 11:41 UTC (permalink / raw)
  To: Vinodh NV <linktovinodh@gmail.com>; +Cc: pgsql-general

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.




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal
@ 2018-02-13 11:42  Francisco Olarte <folarte@peoplecall.com>
  parent: rob stone <floriparob@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Francisco Olarte @ 2018-02-13 11:42 UTC (permalink / raw)
  To: rob stone <floriparob@gmail.com>; +Cc: Vinodh NV <linktovinodh@gmail.com>; pgsql-general

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.




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal
@ 2018-02-13 15:14  Vinodh NV <linktovinodh@gmail.com>
  parent: Francisco Olarte <folarte@peoplecall.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Vinodh NV @ 2018-02-13 15:14 UTC (permalink / raw)
  To: Francisco Olarte <folarte@peoplecall.com>; +Cc: rob stone <floriparob@gmail.com>; pgsql-general

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()");

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.
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal
@ 2018-02-13 16:27  Francisco Olarte <folarte@peoplecall.com>
  parent: Vinodh NV <linktovinodh@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Francisco Olarte @ 2018-02-13 16:27 UTC (permalink / raw)
  To: Vinodh NV <linktovinodh@gmail.com>; +Cc: rob stone <floriparob@gmail.com>; pgsql-general

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.




^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2018-02-13 16:27 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-02-13 08:58 Require assistance in Postgres + Hibernate : Error: java.math.BigInteger cannot be cast to java.math.BigDecimal Vinodh NV <linktovinodh@gmail.com>
2018-02-13 11:39 ` rob stone <floriparob@gmail.com>
2018-02-13 11:42   ` Francisco Olarte <folarte@peoplecall.com>
2018-02-13 15:14     ` Vinodh NV <linktovinodh@gmail.com>
2018-02-13 16:27       ` Francisco Olarte <folarte@peoplecall.com>
2018-02-13 11:41 ` Francisco Olarte <folarte@peoplecall.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox