简体   繁体   English

java.math.BigInteger与java.lang.Long不兼容

[英]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.

相关问题 java.math.BigInteger 无法转换为 java.lang.Long - java.math.BigInteger cannot be cast to java.lang.Long java.lang.Long无法强制转换为java.math.BigInteger - java.lang.Long cannot be cast to java.math.BigInteger java.lang.ClassCastException:java.math.BigInteger无法强制转换为java.lang.Long - java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long 无法将java.math.BigInteger强制转换为java.lang.Long - java.math.BigInteger can't be cast to java.lang.Long 尝试连接后,我一直收到 java.math.bigInteger 无法转换为 java.lang.Long 的问题 - I keept getting a java.math.bigInteger cannot be cast to java.lang.Long iafter trying to connect ClassCastException: java.math.BigInteger 在连接到 MySQL 时不能转换为 java.lang.Long - ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long on connect to MySQL 当我尝试建立与MySQL的连接时,得到以下信息。 java.math.BigInteger不能强制转换为java.lang.Long - I get the following when I try to establish a connection to MySQL. java.math.BigInteger cannot be cast to java.lang.Long Sqoop2无法从mysql导入到hdfs,原因是:“引起原因:java.lang.ClassCastException:java.math.BigInteger无法转换为java.lang.Long” - Sqoop2 failed import from mysql to hdfs with “Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long” 我无法使用JSP文件从MySQL数据库检索数据并收到java.math.BigInteger不能转换为java.lang.Long错误 - I can't retrieve data from MySQL database using a JSP file and receive a java.math.BigInteger cannot be cast to java.lang.Long error java.math.BigInteger的问题 - Problems with java.math.BigInteger
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM