[英]java.math.BigInteger incompatible with java.lang.Long
private List getListByInsuredName(TxnListHelper listHelper) throws DAOException{
Session session = null;
session = getHibernateSession();
String query = "SELECT txnRecNo From TxnInsured WHERE InsuredName LIKE :insuredname";
Query getList = session.createSQLQuery(query);
if(!GenericValidator.isBlankOrNull(listHelper.getInsuredName())){
getList.setParameter("insuredname", "%" + listHelper.getInsuredName() + "%");
}
List txnRecNoList = getList.list();
return txnRecNoList;
}
criteria.add(Restrictions.in("txnRecNo", getListByInsuredName(listHelper)));
txnRecNo is of bigint type field in database i want to add in criteria, and it is showing an exception java.lang.ClassCastException: java.math.BigInteger incompatible with java.lang.Long txnRecNo是数据库中我要添加条件的bigint类型字段,它显示异常java.lang.ClassCastException:java.math.BigInteger与java.lang.Long不兼容
BigInteger can hold an arbitrary amount of data. BigInteger可以容纳任意数量的数据。 It can be way bigger than Long.MAX_VALUE.
它可以比Long.MAX_VALUE大得多。
To convert the value, use txnRecNo.longValue()
要转换该值,请使用
txnRecNo.longValue()
From Java Doc: public int intValue() 从Java Doc:public int intValue()
Converts this BigInteger to an int.
将此BigInteger转换为int。 This conversion is analogous to a narrowing primitive conversion from long to int as defined in section 5.1.3 of The Java™ Language Specification: if this BigInteger is too big to fit in an int, only the low-order 32 bits are returned.
此转换类似于Java™语言规范的5.1.3节中定义的从long到int的窄原始转换:如果此BigInteger太大而无法容纳int,则仅返回低阶32位。 Note that this conversion can lose information about the overall magnitude of the BigInteger value as well as return a result with the opposite sign.
请注意,此转换可能会丢失有关BigInteger值的整体大小的信息,并且会返回带有相反符号的结果。
use intValue()
method to convert BigInteger to long: 使用
intValue()
方法将BigInteger转换为long:
txnRecNo.longValue()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.