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({
    @NamedQuery(
    name = “findBookByAuthor”,
    query = “from Book s where s.author = :author”
    )
    })
Read the full book at www.amazon.com
Posted in Hibernate, Hibernate Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*