Dynamic order by in JPA/Hibernate? -


the naive attempt query this:

query query = em.createquery("from org.domain.resource r r._parent = ? order ?"); 

this not work parameters should data , not column names or syntax asc or desc.

what kind of workarounds have figured out dynamic ordering? concatenating ordering string query string obvious 1 there better ones?

this unfortunately how must done jpa.

i vaguely remember having used numbered parameters (?1, ?2..) ordering native queries (em.createnativequery) on hibernate (but wrong). anyway solution (if using jpa2 or hibernate) use criteria api


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -