java.math.BigInteger cannot be cast to java.lang.Long

本文探讨了在使用Hibernate框架进行数据库查询时遇到的问题:如何将查询结果从BigInteger类型转换为Long类型。通过具体的代码示例,展示了在不同查询方式下返回结果类型的差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mysql数据库

Biginteger 转换为Long类型时的错误


hibernate 的createSQLQuery("select count(*) from orders").uniqueResult() 返回的对象是BigInteger类型的

BigInteger totalCount = (BigInteger)this.getSession().createSQLQuery("select count(*) from orders.orders o, customer.customer c,orders.order_logistics ol where o.customerId=c.id and ol.id=o.collectionToolSendLogisticId and o.valid=true").uniqueResult();


totalCount.intValue()
totalCount.longValue()



createQuery返回的对象是Long类型的

Long totalCount = (Long)this.getSession().createQuery("select count(*) from Special s where s.valid=true").uniqueResult();


本文出自 “点滴积累” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1679032

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值