• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

Converting Derived JPA query into native query: ORDER BY is NOT working

Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have had to convert a couple of derived (keyword-based) queries into corresponding native ones (Postgres sql) and I have noticed the ORDER BY clause does not seem to work. Here are two sample queries:


After a number of tests I came to the conclusion that native queries do not seem to handle well ORDER BY clauses and this causes an issue with my current application. Is there any way to handle them with native queries? Any potential alternative? I would also be happy with converting them back to derived queries.

Thank you
Saloon Keeper
Posts: 23041
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avoid native queries when possible. JPQL is not only database-independent, but also the query optimizer is less likely to provide the performance benefits that JPA can give to its own language. Besides which it's a lot easier to code for table joins!

Having said that, I don't see anything wrong with the SQL you've got working just fine under PostgreSQL. It might not be handled as deftly as a JPQL query would be by JPA, but PostgreSQL definitely knows how to order JOIN results.
A teeny tiny vulgar attempt to get you to buy our stuff
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic