I have the following hql:
Select q FROM GeneralQuestion q
Left Join q.QuestionResponses as qr with qr.ContactUid = :contactuid
WHERE q.ParentUid = :audituid
Obviously GeneralQuestion contains a collection of QuestionResponse objects. I have used the with keyword which I thought would limit the QuestionResponse objects returned to only those QuestionRespone objects with that specific contactuid.
The problem is that each GeneralQuestion stil contains all the QuestionResponses.
Is there a way to limit the QuestionResponse objects returned to be only of that contactuid?
I thought this was the whole point of with and I am now confused.
If you look at the executed SQL, it’s probably retrieving just the filtered records when querying, then lazily reloading the collection when using it.
This makes sense, as NH has to track their state.
What you need to do is retrieve QuestionResponse instances directly in your select list, and that will be your “filtered collection”