0
How can I cast a query for Integer? Follow what I tried to execute.
public Integer validaPrincipal(String usuario, Integer tipo) {
try{
return (Integer) session.getCurrentSession().createNativeQuery("select count(*) from tb_sega_vip_sec where ID_VIP = '"+usuario+"' and TIPO = '"+tipo+"'").getSingleResult();
}catch(Exception e) {
throw new RuntimeException(e);
}
}
and the error made:
Java.lang.RuntimeException: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer
You don’t have to cast
BigDecimal
forInteger
, you need to convert it to int first with the appropriate method, in caseintValue()
.– Andre
So in case I will have to get back to my query and treat it with intValue()?
– Willian Lima