Native SQL Query
Hibernate Native SQL Query
Native SQL is another technique of performing bulk operations on the data using hibernate
By using Native SQL, we can perform both select, non-select operations on the data
Native SQL means using the direct SQL command specific to the particular (current using)
database and executing it with using hibernate
Advantages and Disadvantages of Native SQL
We can use the database specific keywords (commands), to get the data from the database.
While migrating a JDBC program into hibernate, the task becomes very simple because JDBC uses direct SQL commands and hibernate also supports the same commands by using this Native SQL
The main draw back of Native SQL is, some times it makes the hibernate application as
database dependent one
Native SQL
If we want to execute Native SQL Queries on the database then, we need to construct an
object of SQLQuery, actually this SQLQuery is an interface extended from Query and it is
given in ” org.hibernate package "
In order to get an object of SQLQuery, we need to use a method createSQLQuery() given by session interface.
While executing native sql queries on the database, we use directly tables, column names directly in our command.
Remember: while executing Native SQL Queries, even though we are selecting complete objects from the database we need to type cast into object array only, not into our POJO class type, because we are giving direct table, column names in the Native SQL Querie so it does’nt know our class name.
If we execute the command, always first it will put’s data in ResultSet and from there List