Hibernate LeftOuter 加入 HQL
这是我的 left join
hql 查询。执行此代码后,我得到列表大小。但无法将对象强制转换为相应的 pojo 类。
Query query=session.createQuery("from BwClientdetails client left join client.bwClientAllocations");
System.out.println(">>>"+query.list().size());
List<BwClientdetails> list=query.list();
for(int i=0;i<list.size();i++){
BwClientdetails bc=list.get(i);
System.out.println(bc.getClientid());
}
我收到以下错误:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to org.bluewhale.model.BwClientdetails
at testapplication.Main.getClients(Main.java:364)
at testapplication.Main.main(Main.java:54)
This is my left join
hql query. After executing this code i am getting list size. But unable cast object to respective pojo class.
Query query=session.createQuery("from BwClientdetails client left join client.bwClientAllocations");
System.out.println(">>>"+query.list().size());
List<BwClientdetails> list=query.list();
for(int i=0;i<list.size();i++){
BwClientdetails bc=list.get(i);
System.out.println(bc.getClientid());
}
I am getting below error:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to org.bluewhale.model.BwClientdetails
at testapplication.Main.getClients(Main.java:364)
at testapplication.Main.main(Main.java:54)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过不指定 Select 情况,查询的结果是 BwClientdetails、bwClientAllocations 的数组。
在查询前面添加
Select client
应该可以解决您的问题,或者将 for 替换为
始终指定 where 子句是最佳实践,它甚至是 JPA 规范的一部分
By not specifing a Select case, the result of your query is an Array of BwClientdetails, bwClientAllocations.
Adding
Select client
in front of the query should solve your problemor replacing your for by
It's a best practice to alway specify a where clause, it is even part of the JPA spec