
What is Named SQL query in hibernate?

You can put all the HQL into the XML mapping file rather than putting the sql queries to various places in between code.
sample.hbm.xml
<hibernate-mapping>
<class name="com.test.Product" table="product">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="identity" />
</id>
<property name="code" type="string">
<column name="CODE" length="10" not-null="true" unique="true" />
</property>
</class>
<query name="getProductByCode">
<![CDATA[from Product p where p.code = :code]]>
</query>
</hibernate-mapping>
Now you can use it as below:
Query query = session.getNamedQuery("getProductByCode")
.setString("code", "101");

Hi,
See the thread http://roseindia.net/answers/viewqa/Hibernate/15438-Hibernate-named-queries.html
Thanks