1
這情況下,我有:
我有兩個實體一個一對多的關係映射這樣的(只給出相關部分):如何按HQL查詢中的列表進行排序?
<class name="xyz.Survey"> <list name="answers" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan"> <key column="OPA_OP_ID" not-null="true" /> <list-index column="OPA_SORT_ORDER" /> <one-to-many class="xyz.Answer" /> </list> </class> <class name="xyz.Answer"> <many-to-one name="survey" class="xyz.Survey" fetch="select"> <column name="OPA_OP_ID" not-null="true" /> </many-to-one> there is no mapping for column OPA_SORT_ORDER, I let Hibernate take care of that </class>
我的問題是:我想查詢執行HQL單一調查的答案,我希望這些答案按OPA_SORT_ORDER排序。該查詢不起作用這樣的:
select new AnswerDTO(a.id, a.answerText, 0) from Survey p join p.answers a where p.id = ?
在日誌中我可以看到,有沒有這個的HQL產生的ORDER BY在SQL查詢。我怎樣才能做到這一點?我是否需要嚮應答實體添加sortOrder
屬性?
我能做什麼? – RAS 2012-08-17 07:11:29