私はこのような名前付きクエリを書きます
<query name="GET_QUESTIONS_BY_TEST_ID">select tq from TestQuestion as tq inner join tq.question as
q
where
tq.testQuestionIdentifer.versionId=(select
max(tq.testQuestionIdentifer.versionId) from TestQuestion tq_inner
where
tq_inner.testQuestionIdentifer.testId=:testId) and
tq.testQuestionIdentifer.testId=:testId
</query>
そして、私が結果を得るとき、私は問題を抱えています。私が書くとき、私はQuestionオブジェクトとTestQuestionオブジェクトfrom TestQuestion
を取得します。List<Object[Object[]]>
私が書くとき、私 select tq
は得るLazyInitializationException
。リストを取得したいのですが、取得できません。
更新しました
私は自分のhbmの他の部分を追加することにしました
<class name="by.bsuir.testapp.model.TestQuestion" table="TEST_QUESTION"
lazy="true">
<composite-id name="testQuestionIdentifer"
class="by.bsuir.testapp.model.TestQuestionIdentifer">
<key-property name="testId" column="TEST_ID" />
<key-property name="versionId" column="VERSION_ID" />
<key-property name="questionId" column="QUESTION_ID" />
</composite-id>
<many-to-one name="question" class="by.bsuir.testapp.model.Question"
fetch="join" insert="false" update="false">
<column name="QUESTION_ID" />
</many-to-one>
</class>
11.4.1.2. Queries that return tuples
Hibernateドキュメントのドキュメントに存在することがわかりました
厳密な結果を得るために名前付きクエリを作成するにはどうすればよいですか?