I have a List ids populated by database query (Hibernate). The database is PSQL. The ids column is bigint type. Now the ids list is populated without any exception like this
List<Long> ids = getIds();//getIds returns List<Long>
but when I try to loop through the items on the ids list by
for (Long id : ids)
I get the exception
java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
The value is 206131954. I don't know why it can add the value to the list, but later there is the error when trying to go through the list.
public List<Long> getIds() {
List<Long> externalIds = new ArrayList<Long>();
List<Person> persons = repository.getPeople();
for (Person person : persons) {
List<Long> ids = repository.getIdentifications(person);
if (ids.size() > 0) {
externalIds.addAll(ids);
}
}
return externalIds;
}
public List<Long> getIdentifications() {
String q = "select person_id from relevantpeople";
Query query = entityManager.createNativeQuery(q);
return (List<Long>) query.getResultList();
}