简体   繁体   English

如何将nativeQuery列表转换为JPA查询列表?

[英]How to cast nativeQuery list to jpa query list?

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 谢谢

if A is entity, then this should works: 如果A是实体,那么这应该起作用:

TypedQuery<A> query = em.createQuery(sql,A.class);
list1=query.getResultList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM