I'm using JPQL Native query to join table and query result is stored in List<Object[]>.
public String getJoinJpqlNativeQuery() {
String final SQL_JOIN =
"SELECT v1.bitbit, v1.numnum, v1.someTime, t1.username,
t1.anotherNum FROM MasatosanTest t1
JOIN MasatoView v1 ON v1.username = t1.username;"
System.out.println("get join jpql native query is being called
============================");
EntityManager em = null;
List<Object[]> out = null;
try {
em = EmProvider.getDefaultManager();
Query query = em.createNativeQuery(SQL_JOIN);
out = query.getResultList();
System.out.println("return object ==========>" + out);
System.out.println(out.get(0));
String one = out.get(0).toString(); //LINE 77 where ClassCastException
System.out.println(one);
}
catch(Exception e) {
}
finally {
if(em != null) { em.close; }
}
}
The problem is
System.out.println("return object ==========>" + out); outputs:
return object ==========>
[[true, 0, 2010-12-21 15:32:53.0, masatosan, 0.020],
[false, 0, 2010-12-21 15:32:53.0, koga, 0.213]]
System.out.println(out.get(0)) outputs:
[true, 0, 2010-12-21 15:32:53.0, masatosan, 0.020]
So I assumed that I can assign return value of out.get(0) which should be String:
String one = out.get(0).toString();
But I get weird ClassCastException.
java.lang.ClassCastException: java.util.Vector cannot be cast to
[Ljava.lang.Object;
at local.test.jaxrs.MasatosanTestResource.getJoinJpqlNativeQuery
(MasatosanTestResource.java:77)
So what's really going on? Even Object[] foo = out.get(0); would throw an ClassCastException :(