Karthick S
Karthick S

Reputation: 19

Casting Bigdecimal to Integer

i am facing exception in the line

int cdStatus = ((Integer)vecColumns.elementAt(1)).intValue();


 00000050 CommerceSrvr  E com.ibm.commerce.command.ECCommandTarget executeCommand CMN0420E: 
 The following command exception has occurred during processing: "java.lang.ClassCastException: java.math.BigDecimal incompatible with java.lang.Integer". 
 java.lang.ClassCastException: java.math.BigDecimal incompatible with java.lang.Integer
    at com.ibm.commerce.promotion.facade.server.commands.ValidateUniquePromotionCodesTaskCmdImpl.verifyPromotionCodes(ValidateUniquePromotionCodesTaskCmdImpl.java:137)
    at com.ibm.commerce.promotion.facade.server.commands.ValidateUniquePromotionCodesTaskCmdImpl.performExecute(ValidateUniquePromotionCodesTaskCmdImpl.java:84)

Here veColumn is a Vector and the elementAt(1) is an coloumn in the database and of type smallInt in the database side. I am not sure how big decimal come into this picture?

Upvotes: 0

Views: 2839

Answers (2)

fsb
fsb

Reputation: 111

The reason for the unusual behavior is that even though the PX_CDUSAGE defines the column as SMALLINT, it is indeed mapped as a NUMBER(38) in an Oracle database, which, in turn, is represented as a BigDecimal Java object, which explains why vecColumn.elementAt(1) contains a BigDecimal instead of the expected Integer.

further details can be found here: Error description

Now, as a solution, a simple cast to BigDecimal instead of Integer to avoid the ClassCastException, as mpkorstanje correctly pointed out, but since this seems like code you cannot alter, I'd advise to check the indicated fix in the link of disabling the check. It might be the only possible solution without changing the column type.

Upvotes: 2

M.P. Korstanje
M.P. Korstanje

Reputation: 12039

The element you're pulling from the array has the type BigDecimal. You can't cast a BigDecimal to an Integer. Replace the cast to Integer with a cast to BigDecimal and it should work.

Upvotes: 2

Related Questions