Have you tried this?
SELECT c FROM Comment c INNER JOIN FETCH c.user
It gave such error:
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
I read Hibernate doc, and it says:
Nor should fetch be used together with setMaxResults() or setFirstResult() as these operations are based on the result rows, which usually contain duplicates for eager collection fetching, hence, the number of rows is not what you'd expect.
EntityQuery used paging, there's certainly setMaxResults().
I'm kinda confused here. I executed generated mysql from mysql log, and the result seemed correct. Just the transaction was rolled back.
When I specify ejbql="select c from Comment c inner join fetch c.user" in components.xml, the generated ejbql is correct, but to retrieve the count number, it generated "select count(*) from Comment inner join fetch c.user where ......", that's wrong.
There isn't setCountEjbql() method either in EntityQuery or in Query. I have to extend the class. And because there is WHERE clause appended, I too have to recalculate the String, which is annoying and redundant.
Created Jira issue:
And thanks fhh, I think you're correct.