Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Spring MVC, using HQL JOIN i am getting same Data in multiple time

Here, I am joining two tables and get it in List<Confrenceresponse>, But I don't know why my all the list gives only first data in mutiple time(size of list get by query).

  public List<ConferenceResponse> getConferenceResponse(long listId) {
    String hql = "select e.contact as contact, e.name as name, e.ueId as ueId, c.created as created from ExcelDatas e left join 
    channels c on e.contact=c.cid_num where e.ueId = "+listId;
    List<ConferenceResponse> confRe =(List<ConferenceResponse>)getSession().createNativeQuery(hql, ConferenceResponse.class).getResultList();

      for(ConferenceResponse cr:confRe) {
         System.out.println("Name "+cr.getName());
      }
    getSession().flush();
    return confRe;
}

Here, if I am getting 3 join data from table I get first data repeated three times. Can any one solve this? Thanks.

like image 528
Sushil Kumar Avatar asked Jun 03 '26 15:06

Sushil Kumar


1 Answers

Change your HQL to the below one. Also, HQL does not support on keyword.

String hql = "select e.contact as contact, e.name as name, e.ueId as ueId, c.created as created from ExcelDatas e left join 
   e.contact c where e.ueId = "+listId;

If you do not have relationships in entity class, you need to make cross join as follows.

String hql = "select e.contact as contact, e.name as name, e.ueId as ueId, c.created as created from ExcelDatas e,channels c where e.contact=c.cid_num and e.ueId = "+listId;
like image 77
Pooja Aggarwal Avatar answered Jun 06 '26 05:06

Pooja Aggarwal