Reputation: 3988
I have two query list:
List<A> list1;
Query query = em.createQuery(sql);
list1=query.getResultList();
return list1;
and another list is:
List<A> list2;
Query query = em.createNativeQuery(sql);
list2=query.getResultList();
return list2;
when I tried to initialize
list1=list2
which I want to do for my requirement. But I got following exception
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to A
Please help me about this issue. Thanks
Upvotes: 0
Views: 1396
Reputation: 8640
if A is entity, then this should works:
TypedQuery<A> query = em.createQuery(sql,A.class);
list1=query.getResultList();
Upvotes: 1