Jakarta Persistence Query Language
All of our examples that obtain entities from the database so far have conveniently assumed that the primary key for the entity is known ahead of time. We all know that frequently this is not the case. Whenever we need to search for an entity by a field other than the entity’s primary key, we can use the Jakarta Persistence Query Language (JPQL).
JPQL is an SQL-like language used for retrieving, updating, and deleting entities in a database. The following example illustrates how to use JPQL to retrieve a subset of states from the US_STATES
table in the CUSTOMERDB database:
package com.ensode.jakartaeebook.jpql.namedbean; //imports omitted for brevity @Named @RequestScoped public class SelectQueryDemoBean { @PersistenceContext private EntityManager entityManager; private List<UsState> matchingStatesList; public String findStates() { String retVal = "confirmation...