当我尝试运行HQL查询时,我收到以下异常:
java.util.concurrent.ExecutionException: javax.ejb.EJBException:
java.lang.IllegalArgumentException: org.hibernate.QueryException: query specified join
fetching, but the owner of the fetched association was not present in the select list
这是我正在运行的查询:
SELECT new com.airit.propworks.dto.CompanyContactReportDTO(comp, compStatus.statusDesc)
FROM CoCompany as comp
LEFT JOIN FETCH comp.coCompanyCategoriesCompanyNumbers as compCat
LEFT JOIN FETCH comp.coContactCompanyNumbers as compCont
LEFT JOIN FETCH comp.coOperatingNamesCompanyNumbers
LEFT JOIN compCat.categoryFunctionCoCategoryList as compFcn
LEFT JOIN FETCH compCont.coContactDocumentssCompositeFK1 as contDoc
LEFT JOIN FETCH compCont.coContactJobssCompositeFK1 as contJob
LEFT JOIN FETCH compCont.coPhoneNumberssCompositeFK1
LEFT JOIN FETCH contDoc.documentTypeCoDocumentTypes as docTypes
LEFT JOIN FETCH contJob.contactFunctionCoContactFunctions as contFcn
LEFT JOIN comp.companyStatusCoCompanyStatuses as compStatus --this was added by me
WHERE comp.companyNumber = ? ORDER BY comp.companyName
我添加了第二个到最后一行,并且我添加了构造函数。直到我添加了那些我开始获得异常的行。
正如您所看到的,引用comp.companyStatusCoCompanyStatuses
的倒数第二行是一个返回单个CoCompanyStatuses
对象的连接,然后我尝试从中获取statusDesc
字符串并传递给构造
我不确定是什么导致了我得到的异常。你们看到了什么吗?
答案 0 :(得分:1)
使用select new
与join fetch
结合使用opened bug。
由于问题在于添加了select new
,您可以将检索与构建CompanyContactReportDTO
分开。