我这样写命名查询
<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>
当我得到结果时,我遇到了问题。当我写作时,from TestQuestion
我得到List<Object[Object[]]>
了 Question 和 TestQuestion 对象。当我写作时, select tq
我得到LazyInitializationException
. 我想得到 List 但不能。
更新
我决定将其他部分添加到我的 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文档的文档中
我应该如何为 rignt 结果编写命名查询?