InterviewSolution
Saved Bookmarks
| 1. |
Can you tell something about Named SQL Query |
|
Answer» A named SQL query is an expression represented in the form of a table. Here, SQL expressions to select/retrieve rows and columns from one or more tables in one or more DATABASES can be specified. This is like using aliases to the queries. In hibernate, we can make use of @NameQueries and @NameQuery annotations.
Code Snippet: We can define Named Query as shown below @NamedQueries( { @NamedQuery( name = "findIBEmployeeByFullName", query = "from InterviewBitEmployee e where e.fullName = :fullName" ) } ):fullName REFERS to the parameter that is programmer defined and can be set using the query.setParameter method while using the named query. Usage: TypedQuery query = session.getNamedQuery("findIBEmployeeByFullName"); query.setParameter("fullName","Hibernate"); List<InterviewBitEmployee> ibEmployees = query.getResultList();The getNamedQuery method TAKES the name of the named query and returns the query instance. |
|