I am reading a row from the database using JPA, which provides an Object with three int values.
I am now trying to cast this object to an int[]
array, which throws an ClassCastException
and says:
Ljava.lang.Object; cannot be cast to [I
This is my code:
try {
utx.begin();
} catch (NotSupportedException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
Query q = em.createNativeQuery("SELECT * FROM mytable");
List<Object> objectList = q.getResultList();
for (int i = 0; i < objectList.size(); i++) {
Object object = objectList.get(i);
int[] array = (int[]) object;
}
I also tried with Integer[]
. Same exception.
Does someone see the problem? How can I cast it?