My colleague has the following (obviously invalid) JPQL query:
SELECT NEW com.foobar.jpa.DonationAllocationDTOEntity(a.id, a.campaign, a.campAppeal, a.campDivision, a.divisionFund)
FROM DonationAllocation a JOIN a.donation d JOIN a.allocationType t
JOIN FETCH a.campaign
WHERE d.id = :donationId
AND (t.code = 'Pledge' OR t.code = 'MatchingPledge')
It is worth noting (for later in this post) that the relationship DonationAllocationwith the object is Campaignambiguous and is marked as FetchType.LAZY. The goal of my colleague on this request is to (among other things) ensure that it is a.campaign"overstated" (with impatience).
Hibernate (obviously, only one JPA implementation from several), faced with this request, says:
query specified join fetching, but the owner of the fetched association was not present in the select list
This makes sense, since the selection list contains only NEW DonationAllocationDTOEntity(), and section 4.4.5.3 of the JPA 2.0 specification says:
, FETCH JOIN, , , .
, " , " ( DTO, NEW), , FETCH JOIN , , , .
, , JPQL , a.campaign - - ?