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
Post a Comment