Hibernate HQL用于按预定义顺序查找对象的起始索引?
使用HQL,我想搜索序列对象的起始索引 例如,如果我有以下持久化类:Hibernate HQL用于按预定义顺序查找对象的起始索引?,hibernate,jpa,hql,Hibernate,Jpa,Hql,使用HQL,我想搜索序列对象的起始索引 例如,如果我有以下持久化类: <class name="Word"> <id name="id" type="int"> <meta attribute="scope-set">protected</meta> <generator class="native"/> </id> <many-to-one name="se
<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>
我想搜索奶牛,然后返回0和7。搜索跳下的奶牛只会返回0
我目前的方法是迭代搜索——查询第一个单词的索引,然后使用该索引查看以下单词的索引是否符合我的要求。这是一种好方法还是有一种方法可以在一个查询中完成所有操作?这种方法没有任何问题。迭代查询有时是不可避免的 有些数据库返回行号,您可以使用它来构造复杂的查询。我认为hibernate不支持这一点。我知道oracle,postgre>=8.4最有可能的性能将比执行两个查询更差 只需确保不会遇到无穷无尽的查询,或者查询的数量与输入的大小或现有数据的大小成线性增长
<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