Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 132953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:20:40+00:00 2026-05-11T06:20:40+00:00

Using HQL, I would like to search for the starting index of sequenced objects.

  • 0

Using HQL, I would like to search for the starting index of sequenced objects.

For example, if I have the following persisted classes:

<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> 

and I persist the following Words into a Sentence object:

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 

I would like to search for ‘the cow’, and get back 0 and 7. A search for ‘the cow jumped’ would only return 0.

My current approach is an iterative searches — do a query for the index of the first word, then use that index to see if the following words’ indexes are what I want them to be. Is this a good approach or is there a way to do it all in one query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:20:41+00:00Added an answer on May 11, 2026 at 6:20 am

    there is nothing wrong with this approach. iterative queries are sometimes unavoidable.

    there are databases that return the row number and you could maybe use that to contruct a complicated query. i don’t think that hibernate has support for this. (i know of oracle, postgre >= 8.4) most likely the porformance will be worse than doing two queries.

    just make sure that you won’t run into endless queries or the number of queries grows linear with the size of input or size of existing data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write a hql query using a dynamic instantiation with a
I'm using the following HQL query to try and load a set of objects
I would like to perform the following query in HQL: select count(distinct year(foo.date)) from
I'm trying to code the following HQL query using the Criteria API: var userList
I'm using Hibernate criteria and would like to add an order-by clause that is
I have a query created with Hibernate Criteria like this: Criteria criteria = db.getSession().createCriteria(Vendor.class);
I have following Hibernate 3 mapping for User class: <class name=org.test.User table=users> ... some
I need to replicate the following working HQL query using criteria API. session.CreateQuery( select
I am trying to query the following HQL using GORM: MailMessage.executeQuery(toId, count(toId) from (SELECT
Does HQL support conditional expressions in aggregate functions? I would like to do something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.