---
title: "hibernation中，关于fetch的一点异常解决"
author: "843977358"
date: "2015-02-01T07:43:44Z"
tags: []
categories: ["编程语言"]
slug: "hibernation-fetch"
draft: false
lastmod: "2018-09-06T14:31:50Z"
id: 2182014
url: "https://843977358.iteye.com/blog/2182014"
---

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=xxx.trainsystem.pojo.Template}}] \[select g.gradeId,g.grade,g.template.temId,g.template.item,g.template.weight,g.stuAssess.stuAssId from xxx.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到查询返回的对象中。因此当不存在包含时，就会该报错！