O'Reilly logo

Spring Persistence with Hibernate by Ahmad Seddighi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Queries in native SQL

In addition to HQL, Hibernate lets us load persistent objects with native SQL queries. Although using native SQL doesn't seem useful, you may prefer to use native SQL in some situations. For example, you may need to utilize database-specific features which are not supported by HQL. Another situation is when you want to call a stored procedure. Moreover, you may use native SQL when you are migrating from a legacy JDBC-based data tier to Hibernate and need to use SQL in the application. In these cases, either you must use native SQL, or you may prefer to continue working with SQL.

Hibernate provides the org.hibernate.SQLQuery interface to work with SQL queries. To use it, pass the SQL query expression as a String argument to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required