无法将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.