November 2018
Intermediate to advanced
388 pages
9h 5m
English
In the previous section, we discussed how to persist the data to the database using the entity and the entity manager of the JPA. We can also retrieve the data from the database. JPA provides APIs to query the data from the database.
Let's say we want to retrieve the person data that we created and persisted. We could either use CreateNativeQueries, where we can just specify the query using SQL, or we can define a NamedQuery. This is a database query with a specific query syntax and is defined in the entity.
The named queries can be defined as constants and used in the entity class. For example, consider the following code:
const val FIND_ALL_PERSON: String = "Person.findAll"@Table@Entity@NamedQuery(name = FIND_ALL_PERSON, query = ...
Read now
Unlock full access