I'm trying to use Hibernate to retrieve approximately 100 million rows from a table. I have a persisted entity Item that contains a collection of Fees inside (another persisted entity). Given that I will iterate over the result and access the fees for every object, I want to eagerly fetch fees to avoid the n+1 problem.
I should also mention that I want to join it to another table called Provider (one-to-one mapping but no foreign key). I tried:
String query = "select new " + Order.class.getName()
+ "(i, p) from Item i left join fetch i.fees f, Provider p where "
+ "p.factoryId=i.factoryId and p.factoryRef=i.factoryRef";
return session.createQuery(query).scroll();
My Order class contains a Provider field and an Item field. I get this error:
Caused by: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
I would like to end up with a scrollable list of Order which contain Item (with the fees eagerly fetched) and Provider.