带有 NEW 的 JPQL 请求需要太多时间

JPQL request with NEW That takes too much time

我使用 java 并休眠。我尝试在 JPQL 中实现该请求,但与纯 SQL 条件相同

select NEW package.CustomObject(co.num, item, dim, mat, pro) from Object1 co LEFT JOIN co.items item LEFT JOIN item.dim dim LEFT JOIN item.mat mat LEFT JOIN item.pro pro
           where co.ins between '2018-12-26 01:00:00' and '2019-06-26 01:00:00' 
               or co.mod between '2018-12-26 01:00:00' and '2019-06-26 01:00:00'.

自定义对象如下

public class CustomObject {

    private String num;

    private OtherCustomObject other;

    public CustomObject(String num, ItemObject item, DimObject dim, MatObject mat, ProObject pro) {
        this.num = num;
        this.other = new OtherCustomObject(item, dim, mat, pro);
    }

}

public class OtherCustomObject {

    private String property1;
    private String property2;
    private String property3;
    private DimObject  dim;
    private MatObject  mat;
    private ProObject  pro;

    public OtherCustomObject(ItemObject item, DimObject dim, MatObject mat, ProObject pro) {
        this.property1 = item.getProperty1();
        this.property2 = item.getProperty2();
        this.property3 = item.getProperty3();
        this.dim = dim;
        this.mat = mat;
        this.pro = pro; 
    }
}

这是在纯 SQL

中提出的接近相似的等效请求
select  co.num
from    table1    co  left join ItemTable item on item.ou = co.ou left join DimTable dim on dim.item_id = item.id left join MatTable mat on mat.item_id = item.id left join ProTable pro on pro.item_id = item.id 
where   co.ins   between '2018-12-26 01:00:00' and '2019-06-26 01:00:00'
    or  co.mod   between '2018-12-26 01:00:00' and '2019-06-26 01:00:00';

这个请求几乎是即时的。那么我的 JPQL 请求有什么问题吗?

原因是要收集的数据太多。当我运行下面的请求

select co.num from Object1 co LEFT JOIN co.items item LEFT JOIN item.dim dim LEFT JOIN item.mat mat LEFT JOIN item.pro pro
           where co.ins between '2018-12-26 01:00:00' and '2019-06-26 01:00:00' 
               or co.mod between '2018-12-26 01:00:00' and '2019-06-26 01:00:00'.

我有 105 000 个结果。所以服务器缺少内存来呈现其他对象并创建 CustomObject