Hibernate Named Queries Example

Hibernate provides @NamedQueries template using which you can associate unique query name to query.
Since Named Queries are global access , their name should be unique. You can use Named Queries in XML Mappings or using Annotation.

If You are using XML instead of annotation then you can add Named Queries as below in Hibernate hbm.xml file. It should be after Class tags.

       <![CDATA[from Customer cust where cust.customerType = :customerType]]>