在 Spring MVC 中,使用 HQL JOIN 我多次获得相同的数据
In Spring MVC, using HQL JOIN i am getting same Data in multiple time
在这里,我加入两个表并在 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;
如果您在实体 class 中没有关系,则需要按如下方式进行交叉连接。
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;
在这里,我加入两个表并在 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;
如果您在实体 class 中没有关系,则需要按如下方式进行交叉连接。
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;