日期:2014-05-16  浏览次数:20329 次

HIBERNATE 错误

?

?

Hibernate异常:query specified join fetching, but the owner of the fetched association was not present in the select list

?

转至 ???yokubee

?

org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list

?


?

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

?

?

?

[java]?view plaincopy
  1. //这里Student和Teacher为双向多对多关系??
  2. Query?q?=?s.createQuery("select?t?from?Student?s?left?join?fetch?s.teachers?t?where?t.id=1");??
  3. 这时就会报错啦! ?

?