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:
And
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.
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.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
Not so fast naughty spawn! I want you to know about
SKIP - a book about connecting industrious people with elderly land owners