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.
Named queries - JPA Tutorial
From the course: Java Persistence with JPA and Hibernate
Named queries
- [Instructor] Named queries are no different than SQL and JPQL queries. It's just that you are grouping your queries in a single place and later referring to them using predefined names whenever you need to use them. Usually the place you would define your named queries would be your entity classes. The benefit of this is reusability and clean code because queries are no longer scattered in multiple places in your code. A named query is a statically-defined query with a predefined unchangeable query string defined using the @NamedQuery annotation. Let's start by running mariadb-init SQL script, followed by mariadb-07_03 SQL Script. Let's create a named query in the book type entity class. Let's write a simple named query to find all the book types. There are three records in the book_type table. At the top of the BookType entity class, you can place your named query. Write the @NamedQuery annotation, @NamedQuery. It has a name attribute to which you can give a name for your query…
Contents
-
-
-
-
-
-
-
-
-
(Locked)
JPQL queries10m 47s
-
(Locked)
Joins with JPQL9m 11s
-
(Locked)
Named queries5m 15s
-
(Locked)
Aggregate functions8m 43s
-
(Locked)
ORDER BY, GROUP BY, and HAVING9m 17s
-
(Locked)
Native queries5m 11s
-
(Locked)
Criteria queries12m 8s
-
(Locked)
Challenge: Art Class Management app, part 51m 4s
-
(Locked)
Solution: Art Class Management app, part 55m 19s
-
(Locked)
-
-