java - JPA: NamedQuery parameter in query string for switches -
i wondered how in jpa if want call namedquery
stored in entity different settings example order desc or asc use in way parameters (setparameter()
). example not working:
@namedquery(name = "entry.findall", query = "select e entry e e.switch = :switch order e.name :order)
is way use 2 queries like:
@namedquery(name = "entry.findalldesc", query = "select e entry e e.switch = :switch order e.name desc) @namedquery(name = "entry.findallasc", query = "select e entry e e.switch = :switch order e.name asc)
or generate query string in code?
i wondered found no way, because in queries have change such things , make programming style prefer use central namedqueries
stored in entities impossible.
namedquery
static query. can't put dynamic query value (i.e asc or desc) in namedquery
. should use dynamicquery
(i.e. jpql) or native query
or criteria
desired output.
Comments
Post a Comment