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

  • Home
  • SEARCH
  • 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 38447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:42:34+00:00 2026-05-10T14:42:34+00:00

I’m looking for a builder for HQL in Java. I want to get rid

  • 0

I’m looking for a builder for HQL in Java. I want to get rid of things like:

StringBuilder builder = new StringBuilder()     .append('select stock from ')     .append( Stock.class.getName() )     .append( ' as stock where stock.id = ')     .append( id ); 

I’d rather have something like:

HqlBuilder builder = new HqlBuilder()     .select( 'stock' )     .from( Stock.class.getName() ).as( 'stock' )     .where( 'stock.id' ).equals( id ); 

I googled a bit, and I couldn’t find one.

I wrote a quick & dumb HqlBuilder that suits my needs for now, but I’d love to find one that has more users and tests than me alone.

Note: I’d like to be able to do things like this and more, which I failed to do with the Criteria API:

select stock from com.something.Stock as stock, com.something.Bonus as bonus where stock.someValue = bonus.id 

ie. select all stocks whose property someValue points to any bonus from the Bonus table.

Thanks!

  • 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-10T14:42:35+00:00Added an answer on May 10, 2026 at 2:42 pm

    @Sébastien Rocca-Serra
    Now we’re getting somewhere concrete. The sort of join you’re trying to do isn’t really possible through the Criteria API, but a sub-query should accomplish the same thing. First you create a DetachedCriteria for the bonus table, then use the IN operator for someValue.

    DetachedCriteria bonuses = DetachedCriteria.forClass(Bonus.class); List stocks = session.createCriteria(Stock.class)     .add(Property.forName('someValue').in(bonuses)).list(); 

    This is equivalent to

    select stock from com.something.Stock as stock where stock.someValue in (select bonus.id from com.something.Bonus as bonus) 

    The only downside would be if you have references to different tables in someValue and your ID’s are not unique across all tables. But your query would suffer from the same flaw.

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

Sidebar

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.