Scattered HQL string literals in Java code are hard to maintain and look ugly. To avoid it, Hibernate come out a technique called “names queries”, it lets developer to put all HQL into the XML mapping file or via annotation.
XML mapping file:
HQL and Native SQL in annotation
Java Code to use the named Query: