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 8528169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:44:34+00:00 2026-06-11T08:44:34+00:00

I met a problem with SQL. Assume this is my native SQL: SELECT *

  • 0

I met a problem with SQL.

Assume this is my native SQL:

SELECT * FROM products 
ORDER BY balance <= bottleneck DESC, product_code ASC

This is working at postgressql. But it doesn’t work with HQL. My HQL as following:

from Products as p order by  p.balance < p.bottleneck desc, p.productCode asc

And I met exception as following:

Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: < near line 1, column 67 [from com.inventory.inventory.vo.Products as p order by  p.balance < p.bottleneck]
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
    at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760)
    at com.inventory.inventory.dao.impl.ProductsDAOImpl.getProducts(ProductsDAOImpl.java:72)
    at Main.main(Main.java:43)

Is any way to solve for this query?

Your help is much appreciated.

Thanks,
Best rgds,
A1ucard

  • 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. Editorial Team
    Editorial Team
    2026-06-11T08:44:35+00:00Added an answer on June 11, 2026 at 8:44 am

    I haven’t got Hibernate installed right now, but this should work:

    from Products as p where p.balance < p.bottleneck order by p.bottlenec desc, p.productCode asc
    

    This is a more “standard” way of writing SQL because you put order after the where clause.

    Edit:

    There doesn’t seem to be a way to do what you want, at least not using HQL. Postgres has a much more powerful ORDER BY clause than HQL has.

    Postgres documentation on select clause has “ORDER BY expression“, where expression has it’s own documentation page.

    On the other hand, Hibernate’s order by clause is very limited. It allows you to order columns and use regular or aggregate functions.

    The deal killer is this sentence:

    Neither the group by clause nor the order by clause can contain
    arithmetic expressions.

    So, it seems you are out of luck and you must use native SQL if you want to obtain a resultset that you need.

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

Sidebar

Related Questions

I'm new in iOS development, and met this library linking problem in last few
Has anyone met this problem ? I've checked the output of phpinfo() ,and see
In Programming Pearls I have met the following problem. The question is this: print
Hi all: I met a problem like this. Here is the scenario: if I
Just like hold on in Matlab. I met this problem when i want to
Following this question , I've met another problem where the request just doesn't go
I met a problem like this. class A have a list of class B.
I met a problem in Xcode. And my problem was similar to this one:
Never met this problem, and don't know why. The only explanation is a scope
guys. I met this problem this afternoon. I don't want a different span.... My

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.