have you tried casting your value to BigInteger first and then get the long value with longValue()? It should work. And aioobe is right, check for null values also.
I was getting error java.math.BigInteger cannot be cast to java.lang.Long because I was getting the BigInteger while querying using Spring Data native query, so then I've resolved using below code.