My program has a method that fetches the count of a particular row and convert it into BigInteger:
private BigInteger getSameSatPremise(ServiceAgreement sa) {
BigInteger count = BigInteger.ZERO;
StringBuffer queryHql = new StringBuffer();
queryHql.append("from Table t1");
Query query = createQuery(queryHql.toString());
query.addResult("count", "count(distinct t1.column1)");
if (query.listSize() > 0) {
count = (BigInteger) query.firstRow();
}
return count;
}
The casting works fine when the result from the query is 0. But I get a casting error like below when the result from the query is 2.
Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.math.BigInteger
Can anyone help.