I have the below code
StoredProcedureQuery storedProcedure = em.createStoredProcedureQuery("pkg_p.proc_p");
storedProcedure.getResultList();
stored proc returns a ref cursor equivalent to the below query
select 1 as id_col, 'My Name ' as name , 1000 as sal from dual;
I have a pojo class MyTable which is equivalent to the result set return type of the query
public class MyTable {
private Long idCol;
private String name;
private Long sal;
/// setter and getters omitted for brevity
}
for(Object[]row: resultSet)
{
MyTable mt = new MyTable ();
mt.setIdCol((Long)row[0]); ///throw class cast exception
}
How to resolve the below error
Request processing failed; nested exception is java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Long
Even though row[0] has Long values like 1,2,10,687 etc
LongtoNumberfor bothidColandsalor you can simply cast the value toLongby invokinglongValue()method on the object.