Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa 如何仅返回HQL交叉联接中的第一个对象?_Jpa_Hql - Fatal编程技术网

Jpa 如何仅返回HQL交叉联接中的第一个对象?

Jpa 如何仅返回HQL交叉联接中的第一个对象?,jpa,hql,Jpa,Hql,我有以下HQL from com.kable.web.allotment.model.Issue i inner join fetch i.title inner join fetch i.title.magazine inner join fetch i.barcodes bcs , Wholesaler w LEFT join fetch w.localCurrencies c inner join fetch w.loc

我有以下HQL

from 
    com.kable.web.allotment.model.Issue i 
    inner join fetch i.title 
    inner join fetch i.title.magazine 
    inner join fetch i.barcodes bcs 
    , Wholesaler w 
    LEFT join fetch w.localCurrencies c 
    inner join fetch w.location 
where 
    w.id = :wholesalerId
    and i.title.id = :titleid 
    and i.distributionStatus = :status 
    and (
            (
                i.distributionDate is null 
                and i.onSaleDate >= TRUNC(CURRENT_DATE)
            ) 
            or i.distributionDate >= TRUNC(CURRENT_DATE)
        ) 
    and bcs.type.id = w.location.id 
    and (bcs.localCurrency.id = c.localCurrencyType.id OR c.localCurrencyType.id IS NULL) 
    and i.onSaleDate BETWEEN COALESCE(c.effectiveDate, i.onSaleDate) and COALESCE(c.expirationDate, i.onSaleDate) 
order by 
    i.distributionDate
    , i.onSaleDate 

我以前写的所有代码都希望得到一个
列表
,但是有了上面的代码,我也得到了批发商及其联接。在我的结果中,我只想要期刊、标题、杂志和条形码。我使用的是hibernate版本4.2.18.Final。如何仅返回第一个对象图?我在上找到了一些关于交叉连接的信息,但它仅适用于Hibernate 5或更高版本,我无法切换,因为该项目非常大且与Java相关。

您只需添加一个显式的
SELECT I
子句


作为旁注,如果批发商协会的JOIN FETCH无论如何都不会出现在结果中,那么它就没有意义了

您只需要添加一个显式的
SELECT i
子句。作为旁注,
JOIN FETCH
for
批发商
关联没有意义,如果它不会出现在结果中,那么如果您将此作为回答而不是评论,我将接受它。