JPA Named Queries Annotations

Jakarta Persistence (JPA) provides annotations to define static, reusable queries at the class level, separating query logic from business code.

Query definitions

Declare named queries using the following annotations:

Specifies a static, named query in the Jakarta Persistence Query Language (JPQL). It is defined on an entity or mapped superclass and assigned a unique name for retrieval.

A container annotation that groups multiple @NamedQuery definitions on a single class.

Supplies parameters to the persistence provider within a @NamedQuery. Hints can control behavior such as query timeouts, cache usage, or fetch graphs.

For details and examples, see the JPA Named Queries section of the ObjectDB Manual.

Query references

Access named queries in the application by name or by using instances of the following interface:

Represents a named query, including its name, result type, and hints. Retrieve it by result type from EntityManagerFactory.getNamedQueries, and use it to get a TypedQuery instance via EntityManager.createQuery.