How can we use Named Query in Hibernate?

A Named SQL query is the HQL query that is associated with a string name and can be referenced in the application by name.

It can be used in following ways:

  • XML Mapping File: We can define it in XML mapping file.Egg.
  • Annotation: We can also mark Named SQL with annotation.@NamedQueries({
    name = “findBookByAuthor”,
    query = “from Book s where = :author”