Hibernate LeftOuter joins HQL

This is my left joinhql request . After executing this code, I get the size of the list. But the object object could not be applied to the corresponding 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 get 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)
+3
source share
1 answer

Without specifying a selection case, the result of your query is an array of BwClientdetails, bwClientAllocations. Adding Select clientbefore request should solve your problem

Select client from  BwClientdetails  client left  join client.bwClientAllocations

or replace your with

for(int i=0;i<list.size();i++){
   BwClientdetails bc=list.get(i)[0];
   System.out.println(bc.getClientid());
}

It’s best to always specify a where clause, it’s even part of the JPA specification

+2
source

All Articles