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 clie开发者_JAVA百科nt 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)
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 problem
Select client from BwClientdetails client left join client.bwClientAllocations
or replacing your for by
for(int i=0;i<list.size();i++){
BwClientdetails bc=list.get(i)[0];
System.out.println(bc.getClientid());
}
It's a best practice to alway specify a where clause, it is even part of the JPA spec
精彩评论