java – 在Spring MVC中,使用HQL JOIN我多次获得相同的数据

在这里,我正在加入两个表并在List< Confrenceresponse>中获取它,但我不知道为什么我的所有列表仅在多个时间内给出第一个数据(列表的大小通过查询得到).

  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.

最佳答案 将您的HQL更改为以下值.

此外,HQL不支持关键字.

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;

如果您在实体类中没有关系,则需要按如下方式进行交叉连接.

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;
点赞