|
Answer» Named SQL QUERIES are those queries which are defined in mapping file and are called as required anywhere. For example, we can WRITE a SQL query in our XML mapping file as follows: [xml] <sql-query name = “studentdetails”> <return ALIAS=”std”/> SELECT std.STUDENT_ID AS {std.STUDENT_ID}, std.STUDENT_DISCIPLINE AS {std.discipline}, FROM Student std WHERE std.NAME LIKE :name </sql-query> [/xml] Then this query can be called as follows: [java] List students = session.getNamedQuery(&quot;studentdetails&quot;) .setString(&quot;TomBrady&quot;, name) .setMaxResults(50) .list(); [/java] Named SQL queries are those queries which are defined in mapping file and are called as required anywhere. For example, we can write a SQL query in our XML mapping file as follows: [xml] <sql-query name = “studentdetails”> <return alias=”std”/> SELECT std.STUDENT_ID AS {std.STUDENT_ID}, std.STUDENT_DISCIPLINE AS {std.discipline}, FROM Student std WHERE std.NAME LIKE :name </sql-query> [/xml] Then this query can be called as follows: [java] List students = session.getNamedQuery(&quot;studentdetails&quot;) .setString(&quot;TomBrady&quot;, name) .setMaxResults(50) .list(); [/java]
|