无法将java.lang.Integer强制转换为java.math.BigInteger [英] java.lang.Integer cannot be cast to java.math.BigInteger

查看:67
本文介绍了无法将java.lang.Integer强制转换为java.math.BigInteger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是休眠和Mssql的新手.我正在将MySQL与Mssql集成.

I am new in hibernate and Mssql. I am working on MySQL to Mssql integration.

我正面临这个例外:

java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.math.BigInteger

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigInteger

我的代码是:

long salesAlertsCount = ((BigInteger)HibernateUtil.getHibernateSession()
        .createSQLQuery("SELECT COUNT(a.id) FROM Activity as a,Lead as l WHERE a.what_id=l.id and l.deleted=0 and "
        + (currentUser.isAdmin() ? "a.tenant_id="+currentUser.getTenant_id():" (a.owner_id="+currentUser.getId()
        + " or a.createdBy_id="+currentUser.getId()+")")
        + " and "
        + (currentUser.isAdmin()?"l.tenant_id="+currentUser.getTenant_id():" (l.owner_id="+currentUser.getId()+")")
        + " and a.deleted=0 and a.action="
        + Constants.ACTIVITY_ACTION_SEND_SALES_ALERT
        + ""
        + " and a.viewed=0 AND a.created>='"
        + beginingOfMonth
        + "' ").uniqueResult()).longValue();

这是我的代码,以前我在这里停留在MySQL上,但是现在当我集成到Mssql中时,它显示了该异常.

This is my code I am stuck here previously this code working in MySQL but now when I integrate in Mssql it shows that exception.

提前谢谢

推荐答案

这是因为查询返回的是整数,而您正在转换为BigInteger.BigInteger不能转换为Integer,因为BigInteger的主类是Number类型.如果您可以将输出转换为Number,然后将其从Number转换为BigInteger.

this is because the query is returning an integer and you are casting to BigInteger. the BigInteger cannot be cast to Integer because the main class for BigInteger is of type Number. if you could cast the output to Number and from Number you can cast to BigInteger.

这篇关于无法将java.lang.Integer强制转换为java.math.BigInteger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆