Graham
Graham

Reputation: 5904

ExecutionException thrown by HQL Query

I'm getting the following exception when I try to run my HQL query:

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

And here is the query I'm running:

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

The line second to the last was added by me and the constructor was added by me. It wasn't until I added those lines that I started getting the exception.

As you can see the second to last line referring to comp.companyStatusCoCompanyStatuses is a join that returns a single CoCompanyStatuses object that I then try to get the statusDesc string from and pass to the constructor.

I'm not sure what is causing the exception I'm getting. Do you guys see anything?

Upvotes: 1

Views: 379

Answers (1)

yair
yair

Reputation: 9255

There's an opened bug for using select new combined with join fetch.

Since the problem is with the added select new, you can separate the retrieval from constructing CompanyContactReportDTO.

Upvotes: 1

Related Questions