From the course: Java Persistence with JPA and Hibernate

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Native queries

Native queries

- [Instructor] As developers, you might sometimes feel more comfortable with native queries than JPQL queries because when working with JPQL queries, you have to always keep in mind that you are working with entity instances in the context and not with database tables directly. But on the other hand, JPQL is more close to the object-oriented way of doing things. What are native queries? Well, they are queries written directly in the language that your database understands. That is, generally, SQL. But there are certain SQL syntaxes that are DBMS specific. In any case, native queries are queries understood by the underlying database. In general, native queries should be avoided as much as possible in ORM because you will not get some of the out-of-the-box features that an ORM framework like Hibernate gives you, such as caching, checking for SQL injections, query performance, and indexing and et cetera. But there could be times when you might need to use native queries within your ORM…

Contents