May 2018
Intermediate to advanced
310 pages
6h 18m
English
We will give one more example of querying data. We will introduce you to named queries. We will define named queries by using the @NamedQuery annotation applied to our entity class. To give you a better understanding of what we are talking about, we will extend our code. Open the Note class and extend it:
package com.journaler.api.data
...
@Entity
@Table(name = "note")
@JsonInclude(JsonInclude.Include.NON_NULL)
@NamedQuery(
name = "Note.findByTitle",
query = "SELECT n FROM Note n WHERE n.title LIKE ?1"
)
data class Note(
...
) {
...
}
We defined a query that will find all Notes with the title we provide as a parameter through API call. The method that will trigger a query is called findByTitle, so it must be defined in our ...
Read now
Unlock full access