I wondered how to do in JPA if I want to call a NamedQuery
stored in a entity with different settings for example for order DESC or ASC to use in a way like for parameters (setParameter()
). For example this is not working:
@NamedQuery(name = "Entry.findAll", query = "SELECT e FROM Entry e WHERE e.switch = :switch ORDER BY e.name :order)
Is really the only way to use two queries like:
@NamedQuery(name = "Entry.findAllDESC", query = "SELECT e FROM Entry e WHERE e.switch = :switch ORDER BY e.name DESC)
@NamedQuery(name = "Entry.findAllASC", query = "SELECT e FROM Entry e WHERE e.switch = :switch ORDER BY e.name ASC)
or to generate the query string in code?
I wondered that I found no way, because in most queries I have to change such things and this would make a programming style where I prefer to use central NamedQueries
stored in the entities nearly impossible.