1

我目前正在从 hibernate 3 迁移到 4。我设法理清了依赖关系,但我面临着流行的问题:org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list...问题。我曾经执行以下操作以强制 Hibernate 获取整个对象及其集合属性,即具有多个部门的 Employee 和每个部门的地址。

所以在 HQL 我有类似的东西:

select e from Employee as e left join fetch e.department left join fetch e.department.address where e.id= ....

这工作得很好,但在新版本的 Hibernate 中,我只能获取直接属于员工对象而不是部门的属性。我想要的是获取所有属性,因为会话在查询后关闭,并且延迟获取显然会引发异常。

4

1 回答 1

0

I figured out what was needed and I am posting here for others having the same issue.

The query should be:

select e from Employee as e left join fetch e.department as department left join fetch department.address where e.id=...

We have to use an alias department.

于 2013-07-08T09:59:41.263 回答