From the course: Java Persistence API (JPA): 2 Inheritance and Querying

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create native queries

Create native queries

From the course: Java Persistence API (JPA): 2 Inheritance and Querying

Start my 1-month free trial

Create native queries

- [Instructor] Let's learn about writing native queries, and the pros and cons of using native queries to retrieve data. We've seen how rich the syntax of JPQL is, however it only supports a small subset of the SQL standard. Since JPQL is still evolving, some of the important features available in SQL aren't available. Luckily, JPA supports native SQL for more complex queries that are hard to implement in JPQL. The most important thing to understand about native SQL queries created with entity manager methods is that they, like JPL queries, return entity instances rather than database table records. Dynamic native queries can be created easily, similar to how dynamic queries are created. Notice with this native query, we are using SQL instead of JPQL. The entityManager class has a method called createNativeQuery, which makes this possible. You can also create named native queries, similar to how you can create dynamic native queries. Let's see native queries in action. I've opened the…

Contents