1
I need to get the value of a query, simply a field and I’m making the following mistake:
java.math.BigDecimal cannot be cast to java.lang.String.
My DAO is like this:
public String buscaCodColaborador() throws MetrusDAOException{
EntityManager em = null;
try {
StringBuilder sqlString = new StringBuilder();
sqlString
.append(" SELECT LEVEL FROM DUAL CONNECT BY LEVEL <= 9999 ")
.append(" MINUS")
.append(" SELECT COD_COLABORADOR FROM ME_COLABORADORES");
em = getEntityManager();
Query query = em.createNativeQuery(sqlString.toString());
String codColaboradorDisponivel = (String) query.getResultList().get(0);
return codColaboradorDisponivel;
} catch (Exception e) {
logger.error(e, e);
throw new MetrusDAOException(e);
} finally {
closeEntityManager(em);
}
}
I just need to take a bank value and later set in my Business the value returned in a field Long
. I’ve tried using the FindFirst
stream but I’m always taking these conversion errors.
There’s a big decimal in that get(0) there this error is happening at the time of conversion, instead of giving the cast to the string just give a get(0). toString()...
– Lucas Miranda
Thank you @Lucasmiranda this solution solved my problem.
– eugenissimo