hibernation中,关于fetch的一点异常解决

org.hibernate.QueryException: query specified join fetching

Hibernate异常: 
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=null,role=null,tableName=t_template,tableAlias=template1_,origin=t_grade grade0_,columns={grade0_.tempId ,className=glodon.trainsystem.pojo.Template}}] [select g.gradeId,g.grade,g.template.temId,g.template.item,g.template.weight,g.stuAssess.stuAssId from glodon.trainsystem.pojo.Grade g left outer join fetch g.template left outer join fetch g.stuAssess where g.stuAssess.stuAssId =?]
 

报这个异常是因为查询时返回的对象不包含有该join fetch后面的对象,因此可以将fetch删除。这里的fetch就是将fetch后面的对象setter到查询返回的对象中。因此当不存在包含时,就会该报错!

你可能感兴趣的:(fetch)