• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Dynamic sorting on multiple fields and via a parametrised JPA native query [Spring, JPA, Kotlin]

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a requirement whereby my native query would need to have an ORDER BY on potentially multiple sorting fields and directions. I have a native query in my repository that looks something like this (it has been made much simpler than the current one):  



My issue is that `?1` can ideally be matched to multiple fields in my `someTable` whose data types are different. For example, it can be an ID of type UUID as much an integer, etc. Is it possible to perform sorting on multiple fields (over 15 potential ones) and attached directions? I am getting the values of the sorting fields and corresponding directions from a method querying an external service and getting such values from the body of a `ResponseEntity<Any>`.

Thank you
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With SQL you bind variables to values, not column names or chunks of SQL.
So that query won't work anyway.
 
Geane Norm
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:With SQL you bind variables to values, not column names or chunks of SQL.
So that query won't work anyway.



Thanks, is this even possible? Is there any way to achieve that?
reply
    Bookmark Topic Watch Topic
  • New Topic