Before we go on to understand some of the common hibernate operations, let's look into what NamedQuery and Criteria API are. This concept will be referred in the next section for performing data retrieval operations.
NamedQuery in Hibernate is a way to provide alias names to one or more queries, which are static in nature. The primary coding problem that gets solved with NamedQuery is the queries lying all around, and thus, gets difficult to manage. NamedQuery allows queries to be segregated at one place and accessed later via alias names. They are parsed/prepared once, and are thus considered as more optimal than other query mechanisms such as Criteria. NamedQuery can be defined using annotation or mapping files. In this section, we shall take a look at examples using NamedQuery and related annotations.
The following are some of the key annotations in relation with NamedQuery:
@NamedQuery
: This is used to define a Java Persistence...