Join fetch: “query specified join fetching, but the owner of the fetched association was not present in the select list”

亡梦爱人 提交于 2019-12-05 06:22:54

join fetch val.classDAO.b means "when fetching val, also fetch the classDAO linked to the val". But your query doesn't fetch val. It fetches val.code only. So the fetch makes no sense. Just remove it, and everything will be fine:

select distinct val.code from ValueDAO val 
left join val.classDAO classDAO
where classDAO.id = ? 
order by val.code

Some notes, though:

  • doing a left join and then adding a retriction like classDAO.id = ? means that the join is in fact an inner join (since classDAO can't be null and have the given ID at the same time)
  • naming your entities XxxDAO is very confusing. DAOs and entities are not the same thing at all.

Given the above, the query can be rewritten as

select distinct val.code from ValueDAO val 
where val.classDAO.id = ? 
order by val.code
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!