We have an HQL query that is loading an object graph of Questions and
their associated answers, I am attempting to minimize the queries
issued
to the database and have run into an issue. The below query returns
26 records from our testing database, representing 26 valid questions
within our system:
from Question q left join fetch q.QuestionType left join fetch
q.Content qc left join fetch qc.Resources qcr
where qcr is null or
qcr.Language.Id = :CurrentLanguageId or
qcr.Language.Id = :DefaultLanguageId
However, as soon as I attempt to eager fetch the
QuestionXRAnswerOptions, and it's associated content resource entries
(the associated entities that represent our answers in relation to a
question), I begin to get a cartesian result of duplicate questions
entities:
from Question q left join fetch q.QuestionType left join fetch
q.Content qc left join fetch qc.Resources qcr left join fetch
q.QuestionXRAnswerOptions qao left join fetch qao.AnswerOption ao left
join fetch ao.Content aoc left join fetch aoc.Resources aocr
where
(
qcr.Language.Id = :CurrentLanguageId and
aocr.Language.Id
= :CurrentLanguageId) or
(
qcr.Language.Id = :DefaultLanguageId and
aocr.Language.Id
= :DefaultLanguageId) or
(q is null) or
(qao is null)
The QuestionXRAnswerOptions is defined as a map, any suggestions with
the query to eliminate the duplicates? Thanks in advance.