Reputation: 3067
I am trying to run a query with join fetch but I am also using DTO projection to improve performance but I am getting the exception below:
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=pi,role=returnitRest.Ereturn.productItems,tableName=product_item,tableAlias=productite1_,origin=ereturn ereturn0_,columns={ereturn0_.id ,className=returnitRest.ProductItem}}] [SELECT DISTINCT new returnitRest.Ereturn(e.rma, e.shipper, e.carrier, e.returnAction) FROM returnitRest.Ereturn e JOIN FETCH e.productItems pi WHERE e.status = 'RECEIVED' AND e.shipper.email = :shipper AND e.carrier.email = :carrier AND pi.returnAction = :returnAction ]
This is the query:
em.createQuery("SELECT DISTINCT new returnitRest.Ereturn(e.rma, e.shipper, e.carrier, e.returnAction) FROM ereturn e " +
"JOIN FETCH e.productItems pi " +
"WHERE e.status = 'RECEIVED' AND " +
"e.shipper.email = :shipper AND " +
"e.carrier.email = :carrier AND " +
"pi.returnAction = :returnAction ")
.setParameter("shipper", shipperEmail)
.setParameter("carrier", issuer)
.setParameter("returnAction", ReturnAction.valueOf(returnAction))
.getResultList();
QUESTIONS:
thank you very much
Upvotes: 2
Views: 1385
Reputation: 3067
I could not make JOIN to work on a @OneToMany relationship so instead I did the otherway around which is using the @ManyToOne relationship. This way worked for me.
Upvotes: 0
Reputation: 16430
You don't need a join fetch here, you are not even using the product item in the DTO. A normal join would be enough, that way, you also won't see that error.
Upvotes: 2