在响应参数中使用点的Hql查询 [英] Hql query using dot´s in the response parameters
问题描述
我使用Dto与一些实体访问数据库,并且我希望改进请求而不修改我的dto并删除fetch,所以hibernate不会返回所有实体的所有数据(hibernate设置为lazy) ,我尝试了下一个,但它不起作用:
I am accesing to the database using a Dto with some entities and I want to improve the request without modifing my dto and removing the fetch so hibernate don´t return all the data from all the entities (hibernate is set to lazy), I tried with the next, but it´s not working:
StringBuilder hql = new StringBuilder();
hql.append(" select d.id as id, ce.cod as clasification.cod ");
hql.append(" from Document d");
hql.append(" join d.clasificacionEntity ce");
工作的hql请求:
The working hql request:
StringBuilder hql = new StringBuilder();
hql.append(" select d");
hql.append(" from Document d");
hql.append(" join fetch d.clasificacionEntity ce");
问题是当我尝试使用ce.cod as clasification.cod时,第二个点给出我错了,还有其他方法可以做到吗? ,非常感谢!!!
The problem is when I try to use "ce.cod as clasification.cod" the second dot gives me a error, there is other way to do that? , thanks a lot!!!
我的dto结果是:
My dto result is:
DocumentDto{
private id
private clasificacionEntityDto;
}
And
clasificacionEntityDto {
private cod
}
推荐答案
最后,我只是创建一个dto,如下所示:
At the end I just create a dto like this:
DocumentDto{
private id
private String clasificacionEntityDtoCod;
}
并将其设置为:
StringBuilder hql = new StringBuilder();
hql.append(" select d.id as id, ce.cod as clasificacionEntityDtoCod ");
hql.append(" from Document d");
hql.append(" join d.clasificacionEntity ce");
这篇关于在响应参数中使用点的Hql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!