使用 HQL,我想搜索排序对象的起始索引。
例如,如果我有以下持久类:
<class name="Word">
<id name="id" type="int">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<many-to-one name="sentence" class="Sentence"/>
<property name="word" type="string"/>
<property name="num" type="integer"/>
</class>
<class name="Sentence">
<id name="id" type="int">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<set name="words" lazy="true">
<one-to-many class="Word"/>
</set>
</class>
我将以下单词持久化到一个句子对象中:
WORD NUM
----------
the 0
cow 1
jumped 2
over 3
the 4
moon 5
but 6
the 7
cow 8
forgot 9
her 10
bell 11
我想搜索“the cow”,然后返回 0 和 7。搜索“the cow jumped”只会返回 0。
我目前的方法是迭代搜索——查询第一个单词的索引,然后使用该索引查看以下单词的索引是否是我想要的。这是一种好方法还是有办法在一个查询中完成所有操作?