JPA Queries
Jakarta Persistence provides powerful APIs for executing database queries using JPQL strings or the programmatic Criteria API. These interfaces support both static and dynamic query construction with full type safety.
General query objects
Execute SELECT, UPDATE and DELETE queries in JPA using these core interfaces:
The base interface for executing queries in JPA. It is often replaced by TypedQuery in modern applications to ensure compile-time type safety.
A sub-interface of Query used for queries where the result type is known. It is preferred over the legacy Query interface because it eliminates the need for casting results.
Controls the execution of stored procedures (not applicable to ObjectDB).
Interface for declaring and handling named or positional query parameters.
Use EntityManagerjakarta.persistence.EntityManagerInterface used to interact with the persistence context. methods such as createQuery to build query objects using:
- Direct JPQL query strings ("SELECT ... FROM ... WHERE ..."); or
- Criteria query objects, as described below.
For detailed usage instructions, refer to the JPA Query API section in the ObjectDB manual.
Criteria query API
The Criteria API provides a factory for defining queries programmatically using Java objects rather than string-based JPQL. Criteria queries are built using CriteriaBuilder:
This is the main factory for creating criteria queries and their elements (predicates, expressions, etc.). Obtain it from EntityManagerFactoryjakarta.persistence.EntityManagerFactoryInterface used to interact with the persistence unit, and to create new instances of EntityManager . or EntityManagerjakarta.persistence.EntityManagerInterface used to interact with the persistence context. using the getCriteriaBuilder method.
Additional components for building criteria queries are described in the following subsections:
Interfaces that represent the query structure itself (SELECT, UPDATE, or DELETE) and provide methods for refining the query clauses.
Elements used to define the SELECT and ORDER BY clauses.
Elements for the FROM clause, representing roots, joins, and fetches.
General expressions used within query logic, such as predicates for the WHERE clause, mathematical operations, and conditional logic.
Helper interfaces for manipulating temporal expressions and date/time components.