After upgrading to a newer hibernate version (guess it came with the switch from JBoss 4.2.2 to JBoss 6), some queries fail with the message:
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= (...)
This is always the case when using a query like this:
SELECT entityA FROM EntityA entityA
JOIN FETCH entityA.entityB
LEFT JOIN FETCH entityA.entityB.someField
WHERE entityA.entityB.anotherField LIKE :someParameter
The solution to the problem is to give "entityA.entityB" an alias and then to use this alias in the WHERE
clause. But in some queries the LEFT JOIN FETCH
is not explicitely given but still the WHERE
clause uses the property of a referenced entity. Will it also fail there? What has changed, so that it suddenly fails after switching to a new JBoss version?
The following question is related to this question and includes the solution, but doesn't explain the problem.
The query should be
SELECT entityA FROM EntityA entityA
JOIN FETCH entityA.entityB entityB
LEFT JOIN FETCH entityB.someField
WHERE entityB.anotherField LIKE :someParameter
I.e. you should assign an alias to each joined entity, and use this alias for subsequent joins or restrictions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With