升级到更新的休眠版本后(猜测它是从 JBoss 4.2.2 切换到 JBoss 6 时附带的),一些查询失败并显示以下消息:
Caused by: java.lang.IllegalArgumentException: 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= (...)
使用这样的查询时总是会出现这种情况:
SELECT entityA FROM EntityA entityA
JOIN FETCH entityA.entityB
LEFT JOIN FETCH entityA.entityB.someField
WHERE entityA.entityB.anotherField LIKE :someParameter
该问题的解决方案是给“entityA.entityB”一个别名,然后在WHERE
子句中使用这个别名。但是在某些查询中,LEFT JOIN FETCH
没有明确给出,但WHERE
子句仍然使用引用实体的属性。那里也会失败吗?发生了什么变化,以至于切换到新的 JBoss 版本后突然出现故障?
以下问题与此问题相关,包括解决方案,但不解释问题。