InterviewSolution
Saved Bookmarks
| 1. |
Does Hibernate support Native SQL Queries? |
|
Answer» Yes, it does. HIBERNATE provides the createSQLQuery() METHOD to let a developer call the native SQL statement directly and returns a Query object. Consider the example where you want to get employee data with the full name “Hibernate”. We don’t want to use HQL-based features, instead, we want to write our own SQL QUERIES. In this case, the code would be: Query query = session.createSQLQuery( "select * from interviewbit_employee ibe where ibe.fullName = :fullName") .addEntity(InterviewBitEmployee.class) .setParameter("fullName", "Hibernate"); //named parametersList result = query.list();Alternatively, native queries can also be supported when USING NamedQueries. |
|