diff --git a/api/src/main/java/jakarta/persistence/QueryFlushMode.java b/api/src/main/java/jakarta/persistence/QueryFlushMode.java
index 8859a6fe6..79660454b 100644
--- a/api/src/main/java/jakarta/persistence/QueryFlushMode.java
+++ b/api/src/main/java/jakarta/persistence/QueryFlushMode.java
@@ -76,6 +76,7 @@
* @see NamedQuery#flush
* @see NamedNativeQuery#flush
* @see jakarta.persistence.query.QueryOptions#flush
+ * @see jakarta.persistence.query.StatementOptions#flush
* @see FlushModeType
*/
public enum QueryFlushMode
@@ -115,4 +116,4 @@ public enum QueryFlushMode
* persistence context.
*/
DEFAULT
-}
\ No newline at end of file
+}
diff --git a/api/src/main/java/jakarta/persistence/QueryHint.java b/api/src/main/java/jakarta/persistence/QueryHint.java
index b9a88f682..9ec2354e6 100644
--- a/api/src/main/java/jakarta/persistence/QueryHint.java
+++ b/api/src/main/java/jakarta/persistence/QueryHint.java
@@ -21,6 +21,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import jakarta.persistence.query.QueryOptions;
+import jakarta.persistence.query.StatementOptions;
/**
* Supplies a property or hint via an annotation.
@@ -31,7 +32,8 @@
* {@link NamedNativeStatement#hints @NamedNativeStatement},
* {@link NamedStatement#hints @NamedStatement},
* {@link NamedStoredProcedureQuery#hints @NamedStoredProcedure},
- * or {@link QueryOptions#hints @QueryOptions},
+ * {@link QueryOptions#hints @QueryOptions}, or
+ * {@link StatementOptions#hints @StatementOptions},
* this annotation specifies a query hint.
*
As a nested annotation of {@link Fetch#hints @Fetch},
* it specifies a fetching hint.
@@ -46,6 +48,7 @@
* @see NamedStatement#hints
* @see NamedStoredProcedureQuery#hints
* @see QueryOptions#hints
+ * @see StatementOptions#hints
* @see Fetch#hints
*
* @since 1.0
diff --git a/api/src/main/java/jakarta/persistence/Reference.java b/api/src/main/java/jakarta/persistence/Reference.java
index 29e32a3d0..c41d0b3dc 100644
--- a/api/src/main/java/jakarta/persistence/Reference.java
+++ b/api/src/main/java/jakarta/persistence/Reference.java
@@ -23,9 +23,12 @@
/**
* A reference to a named statement or query declared via the
- * {@link NamedQuery} or {@link NamedNativeQuery} annotations,
- * or using {@link jakarta.persistence.query.JakartaQuery} or
- * {@link jakarta.persistence.query.NativeQuery}. An
+ * {@link NamedQuery}, {@link NamedNativeQuery}, {@link NamedStatement},
+ * or {@link NamedNativeStatement} annotations, or using
+ * {@link jakarta.persistence.query.JakartaQuery},
+ * {@link jakarta.persistence.query.NativeQuery},
+ * {@link jakarta.persistence.query.JakartaStatement}, or
+ * {@link jakarta.persistence.query.NativeStatement}. An
* instance of {@code Reference} is usually obtained from the
* static metamodel. This interface declares operations common
* to {@link StatementReference} and {@link TypedQueryReference}.
@@ -37,10 +40,13 @@ public sealed interface Reference
/**
* The name of the statement or query, as specified by
- * {@link NamedQuery#name} or {@link NamedNativeQuery#name},
+ * {@link NamedQuery#name}, {@link NamedNativeQuery#name},
+ * {@link NamedStatement#name}, or {@link NamedNativeStatement#name},
* or as inferred from the name of the method annotated
- * {@link jakarta.persistence.query.JakartaQuery} or
- * {@link jakarta.persistence.query.NativeQuery}.
+ * {@link jakarta.persistence.query.JakartaQuery},
+ * {@link jakarta.persistence.query.NativeQuery},
+ * {@link jakarta.persistence.query.JakartaStatement}, or
+ * {@link jakarta.persistence.query.NativeStatement}.
*/
@Nullable
String getName();
@@ -107,7 +113,9 @@ public sealed interface Reference
/**
* A map keyed by hint name of all hints specified via
* {@link NamedQuery#hints}, {@link NamedNativeQuery#hints},
- * or {@link jakarta.persistence.query.QueryOptions#hints}.
+ * {@link NamedStatement#hints}, {@link NamedNativeStatement#hints},
+ * {@link jakarta.persistence.query.QueryOptions#hints}, or
+ * {@link jakarta.persistence.query.StatementOptions#hints}.
*
* Any attempted mutation of the returned map results in an
* {@link UnsupportedOperationException}.
diff --git a/api/src/main/java/jakarta/persistence/StatementReference.java b/api/src/main/java/jakarta/persistence/StatementReference.java
index 65c2bc189..45c23e78c 100644
--- a/api/src/main/java/jakarta/persistence/StatementReference.java
+++ b/api/src/main/java/jakarta/persistence/StatementReference.java
@@ -22,9 +22,9 @@
/**
* A reference to an executable named statement for an operation
* that returns a row count. The named statement is declared via the
- * {@link NamedQuery} or {@link NamedNativeQuery} annotations,
- * or using {@link jakarta.persistence.query.JakartaQuery} or
- * {@link jakarta.persistence.query.NativeQuery}. An
+ * {@link NamedStatement} or {@link NamedNativeStatement} annotations,
+ * or using {@link jakarta.persistence.query.JakartaStatement} or
+ * {@link jakarta.persistence.query.NativeStatement}. An
* instance of {@code StatementReference} is usually obtained
* from the static metamodel of the annotated type.
*
@@ -35,7 +35,7 @@
* class Filer {
* @Inject EntityManager entityManager;
*
- * @JakartaQuery("delete from Record where temporary = true")
+ * @JakartaStatement("delete from Record where temporary = true")
* int purgeTemporaryRecords() {
* return entityManager.createStatement(Filer_.purgeTemporaryRecords())
* .execute();
@@ -44,15 +44,15 @@
* }
*
*
In this example, the entity class is annotated,
- * and the {@link NamedQuery} annotation explicitly specifies a
+ * and the {@link NamedStatement} annotation explicitly specifies a
* name:
* {@snippet :
- * @NamedQuery(name = "updateSales",
- * query = "update Book set sales = ?1 where isbn = ?2")
+ * @NamedStatement(name = "updateSales",
+ * statement = "update Book set sales = ?1 where isbn = ?2")
* @Entity class Book { .. }
* }
*
In this case the {@code StatementReference} obtained from
- * its static metamodel does not include arguments to the query
+ * its static metamodel does not include arguments to the statement
* parameters, and so they must be supplied via {@code setParameter}:
* {@snippet :
* int updated =
@@ -63,13 +63,13 @@
* }
*
*
A {@code StatementReference} may include arguments to parameters
- * of the query.
+ * of the statement.
*
- *
A reference representing a query declared using an
+ *
A reference representing a statement declared using an
* annotation of a type or field has no arguments, and so
* {@link #getArguments()}, {@link #getParameterNames()},
* and {@link #getParameterTypes()} all return {@code null}.
- *
A reference representing a query declared using an
+ *
A reference representing a statement declared using an
* annotation of a method holds information about the
* arguments passed to the method, making it available via
* {@link #getArguments()}, {@link #getParameterNames()},
@@ -92,14 +92,14 @@
public non-sealed interface StatementReference extends Reference {
/**
* All {@linkplain Statement.Option options} specified by
- * {@link jakarta.persistence.query.QueryOptions},
- * {@link NamedQuery}, or {@link NamedNativeQuery}, or an
+ * {@link jakarta.persistence.query.StatementOptions},
+ * {@link NamedStatement}, or {@link NamedNativeStatement}, or an
* empty set if no options were specified.
*
* @see Statement#addOption
- * @see jakarta.persistence.query.QueryOptions#timeout
- * @see jakarta.persistence.query.QueryOptions#flush
+ * @see jakarta.persistence.query.StatementOptions#timeout
+ * @see jakarta.persistence.query.StatementOptions#flush
*/
@Nonnull
Set getOptions();
-}
\ No newline at end of file
+}
diff --git a/api/src/main/java/jakarta/persistence/metamodel/StaticMetamodel.java b/api/src/main/java/jakarta/persistence/metamodel/StaticMetamodel.java
index 0efb73e11..51b2fa422 100644
--- a/api/src/main/java/jakarta/persistence/metamodel/StaticMetamodel.java
+++ b/api/src/main/java/jakarta/persistence/metamodel/StaticMetamodel.java
@@ -31,11 +31,15 @@
* {@link #value} element. The Java type might be:
*
*
an entity class, mapped superclass, or embeddable class,
- *
a class with one or more {@link jakarta.persistence.NamedQuery}
- * or {@link jakarta.persistence.NamedNativeQuery} annotations, or
+ *
a class with one or more {@link jakarta.persistence.NamedQuery},
+ * {@link jakarta.persistence.NamedNativeQuery},
+ * {@link jakarta.persistence.NamedStatement}, or
+ * {@link jakarta.persistence.NamedNativeStatement} annotations, or
*
a class with one or more methods annotated
- * {@link jakarta.persistence.query.JakartaQuery} or
- * {@link jakarta.persistence.query.NativeQuery}.
+ * {@link jakarta.persistence.query.JakartaQuery},
+ * {@link jakarta.persistence.query.NativeQuery},
+ * {@link jakarta.persistence.query.JakartaStatement}, or
+ * {@link jakarta.persistence.query.NativeStatement}.
*
*
*
Typically, a static metamodel class is generated by an annotation
diff --git a/api/src/main/java/jakarta/persistence/query/JakartaQuery.java b/api/src/main/java/jakarta/persistence/query/JakartaQuery.java
index 39c566b61..b775cab9f 100644
--- a/api/src/main/java/jakarta/persistence/query/JakartaQuery.java
+++ b/api/src/main/java/jakarta/persistence/query/JakartaQuery.java
@@ -22,7 +22,9 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
- * Specifies a query expressed in the Jakarta Persistence Query Language.
+ * Specifies a {@code SELECT} query expressed in the Jakarta Persistence
+ * Query Language. An {@code UPDATE} or {@code DELETE} statement must be
+ * declared using {@link JakartaStatement}.
* This annotation may be applied to:
*
*
any method of any class or interface belonging to the persistence
@@ -55,10 +57,6 @@
* where title like = ?1 and pubDate > ?2
* """)
* List retrieveSummaries(String title, LocalDate fromDate);
- *
- * @JakartaQuery("delete from Trash")
- * @QueryOptions(timeout = 30_000)
- * int emptyTrash();
* }
*}
*
@@ -87,10 +85,6 @@
* In the second case, each query result is automatically packaged in a new
* instance of the result class by calling the matching constructor.
*
- *
A method return type agrees with the type returned by an
- * {@code UPDATE} or {@code DELETE} statement if the return type is
- * {@code void}, {@code int}, or {@code long}.
- *
*
A method parameter type agrees with a query parameter type if
* it is a type that could be assigned to the corresponding query parameter
* by passing an instance of the type to {@code setParameter()}. In making
@@ -124,12 +118,6 @@
* em.createQuery(Library_.getBookWithIsbn(isbn))
* .getSingleResult();
* }
- * {@snippet :
- * int deleted =
- * em.createQuery(Library_.emptyTrash())
- * .executeUpdate();
- * }
- *
*
In addition, the query is treated as a named query, where the query
* name agrees with the convention for Javadoc links, that is: the
* concatenation of the fully qualified name of the type, with the string
@@ -138,7 +126,13 @@
* example, {@code "org.example.Library#findBooksByTitle(java.lang.String)"}.
*
*
The persistence provider must treat the annotation
- * {@code jakarta.data.repository.Query} as a synonym for this annotation.
+ * {@code jakarta.data.repository.Query} as a synonym for this annotation
+ * when it specifies a {@code SELECT} query. A method must not be annotated
+ * with more than one of {@code JakartaQuery}, {@code JakartaStatement},
+ * {@code NatveQuery}, {@code NativeStatement}, and {@code Query}.
+ *
+ * @see JakartaStatement
+ * @see QueryOptions
*
* @since 4.0
*/
@@ -149,4 +143,4 @@
* The query string in the Jakarta Persistence Query Language.
*/
String value();
-}
\ No newline at end of file
+}
diff --git a/api/src/main/java/jakarta/persistence/query/JakartaStatement.java b/api/src/main/java/jakarta/persistence/query/JakartaStatement.java
new file mode 100644
index 000000000..b453dd9c2
--- /dev/null
+++ b/api/src/main/java/jakarta/persistence/query/JakartaStatement.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2026 Contributors to the Eclipse Foundation
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0,
+ * or the Eclipse Distribution License v. 1.0 which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
+ */
+
+// Contributors:
+// Gavin King - 4.0
+
+package jakarta.persistence.query;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Specifies an {@code UPDATE} or {@code DELETE} statement expressed in
+ * the Jakarta Persistence Query Language. A {@code SELECT} query must be
+ * declared using {@link JakartaQuery}.
+ * This annotation may be applied to:
+ *
+ *
any method of any class or interface belonging to the persistence
+ * unit, or
+ *
a query method of a Jakarta Data repository with an implementation
+ * backed by Jakarta Persistence.
+ *
+ *
The return type of the method must be {@code void}, {@code int},
+ * or {@code long}. The parameter types of the method must agree with the
+ * types of the statement parameters. An implementation of Jakarta
+ * Persistence or of Jakarta Data may be able to determine if such
+ * agreement exists at compilation time or when the persistence unit is
+ * initialized, but this is not required.
+ *
+ *
A method parameter type agrees with a statement parameter
+ * type if it is a type that could be assigned to the corresponding
+ * statement parameter by passing an instance of the type to
+ * {@code setParameter()}. In making this determination, method parameters
+ * are correlated with statement parameters by position or by name,
+ * depending on whether the statement uses positional or named parameters.
+ *
+ *
The parameter types of the annotated method must be basic types.
+ * If this annotation occurs on a generic method, on a method with a
+ * parameter type which is not a basic type, or on a method with a
+ * parameter type involving a type variable, the behavior is undefined.
+ *
+ *
Any implementation of Jakarta Data backed by Jakarta Persistence
+ * must support the use of this annotation as a Jakarta Data query
+ * annotation. Thus, a repository method annotated {@code @JakartaStatement}
+ * is treated by the Jakarta Data provider as a query method, and an
+ * implementation of the method is supplied by the Jakarta Data provider.
+ *
+ *
When this annotation is applied to a method of a class or interface
+ * belonging to the persistence unit, a reference to a statement declared
+ * using this annotation may be obtained from the static metamodel class
+ * of the annotated class or interface.
+ * {@snippet :
+ * int deleted =
+ * em.createStatement(Library_.emptyTrash())
+ * .execute();
+ * }
+ *
+ *
In addition, the statement is treated as a named statement, where
+ * the statement name agrees with the convention for Javadoc links, that
+ * is: the concatenation of the fully qualified name of the type, with
+ * the string {@code #}, the name of the annotated member, and the raw
+ * types of the method parameters, enclosed in parentheses and separated
+ * by commas, for example, {@code "org.example.Library#emptyTrash()"}.
+ *
+ *
The persistence provider must treat the annotation
+ * {@code jakarta.data.repository.Query} as a synonym for this annotation
+ * when it specifies an {@code UPDATE} or {@code DELETE} statement. A
+ * method must not be annotated with more than one of {@code JakartaQuery},
+ * {@code JakartaStatement}, {@code NatveQuery}, {@code NativeStatement},
+ * and {@code Query}.
+ *
+ * @see JakartaQuery
+ * @see StatementOptions
+ *
+ * @since 4.0
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+public @interface JakartaStatement {
+ /**
+ * The statement string in the Jakarta Persistence Query Language.
+ */
+ String value();
+}
diff --git a/api/src/main/java/jakarta/persistence/query/NativeQuery.java b/api/src/main/java/jakarta/persistence/query/NativeQuery.java
index 796c1eb8b..3af68e51e 100644
--- a/api/src/main/java/jakarta/persistence/query/NativeQuery.java
+++ b/api/src/main/java/jakarta/persistence/query/NativeQuery.java
@@ -23,6 +23,8 @@
/**
* Specifies a query expressed in the native SQL dialect of the database.
+ * The SQL query must return a result set. A SQL statement that returns a
+ * row count must be declared using {@link NativeStatement}.
* This annotation may be applied to:
*
*
any method of any class or interface belonging to the persistence
@@ -46,11 +48,6 @@
*
* @NativeQuery("select * from books where isbn = ?")
* Book getBookWithIsbn(String isbn);
- *
- * @NativeQuery("delete from documents"
- * + " where id in (select document_id from trash)")
- * @QueryOptions(timeout = 30_000)
- * int emptyTrash();
* }
*}
*
A method return type agrees with an explicitly specified
@@ -64,8 +61,8 @@
* mapping, as specified by Jakarta Data.
*
*
- *
If the SQL statement returns a result set and no explicit result set
- * mapping is specified using {@link jakarta.persistence.EntityResult},
+ *
If no explicit result set mapping is specified using
+ * {@link jakarta.persistence.EntityResult},
* {@link jakarta.persistence.ColumnResult}, or
* {@link jakarta.persistence.ConstructorResult}, the query result class
* must be inferred from the return type of the annotated method. For a
@@ -83,10 +80,6 @@
* List findBookRecordsByTitle(String title);
* }
*
- *
A method return type agrees with the type returned by a
- * SQL statement that returns a row count if the return type is
- * {@code void}, {@code int}, or {@code long}.
- *
*
A method parameter type agrees with a query parameter type if it is
* a type that could be assigned to the corresponding query parameter by
* passing an instance of the type to {@code setParameter()}. In making
@@ -120,12 +113,6 @@
* em.createQuery(Library_.getBookWithIsbn(isbn))
* .getSingleResult();
* }
- * {@snippet :
- * int deleted =
- * em.createQuery(Library_.emptyTrash())
- * .executeUpdate();
- * }
- *
*
In addition, the query is treated as a named query, where the query
* name agrees with the convention for Javadoc links, that is: the
* concatenation of the fully qualified name of the type, with the string
@@ -158,6 +145,13 @@
* in the order in which they are declared.
*
*
+ *
A method must not be annotated with more than one of
+ * {@code JakartaQuery}, {@code JakartaStatement}, {@code NatveQuery},
+ * {@code NativeStatement}, and {@code jakarta.data.repository.Query}.
+ *
+ * @see NativeStatement
+ * @see QueryOptions
+ *
* @since 4.0
*/
@Target(METHOD)
diff --git a/api/src/main/java/jakarta/persistence/query/NativeStatement.java b/api/src/main/java/jakarta/persistence/query/NativeStatement.java
new file mode 100644
index 000000000..f5c309db7
--- /dev/null
+++ b/api/src/main/java/jakarta/persistence/query/NativeStatement.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2026 Contributors to the Eclipse Foundation
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0,
+ * or the Eclipse Distribution License v. 1.0 which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
+ */
+
+// Contributors:
+// Gavin King - 4.0
+
+package jakarta.persistence.query;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Specifies a statement expressed in the native SQL dialect of the
+ * database. The SQL statement must return a row count. A SQL query that
+ * returns a result set must be declared using {@link NativeQuery}.
+ * This annotation may be applied to:
+ *
+ *
any method of any class or interface belonging to the persistence
+ * unit, or
+ *
a query method of a Jakarta Data repository with an implementation
+ * backed by Jakarta Persistence.
+ *
+ *
The return type of the method must be {@code void}, {@code int},
+ * or {@code long}. The parameter types of the method must agree with the
+ * types of the statement parameters. It is not usually possible to
+ * determine if the parameter types agree without executing the native
+ * SQL statement.
+ *
+ *
+ * {@snippet :
+ * interface Library {
+ * @NativeStatement("delete from documents"
+ * + " where id in (select document_id from trash)")
+ * @StatementOptions(timeout = 30_000)
+ * int emptyTrash();
+ * }
+ * }
+ *
+ *
A method parameter type agrees with a statement parameter
+ * type if it is a type that could be assigned to the corresponding
+ * statement parameter by passing an instance of the type to
+ * {@code setParameter()}. In making this determination, method parameters
+ * are correlated with statement parameters by position or by name,
+ * depending on whether the statement uses positional or named parameters.
+ *
+ *
The parameter types of the annotated method must be basic types.
+ * If this annotation occurs on a generic method, on a method with a
+ * parameter type which is not a basic type, or on a method with a
+ * parameter type involving a type variable, the behavior is undefined.
+ *
+ *
Any implementation of Jakarta Data backed by Jakarta Persistence
+ * must support the use of this annotation as a Jakarta Data query
+ * annotation. Thus, a repository method annotated {@code @NativeStatement}
+ * is treated by the Jakarta Data provider as a query method, and an
+ * implementation of the method is supplied by the Jakarta Data provider.
+ *
+ *
When this annotation is applied to a method of a class or interface
+ * belonging to the persistence unit, a reference to a statement declared
+ * using this annotation may be obtained from the static metamodel class
+ * of the annotated class or interface.
+ * {@snippet :
+ * int deleted =
+ * em.createStatement(Library_.emptyTrash())
+ * .execute();
+ * }
+ *
+ *
In addition, the statement is treated as a named statement, where
+ * the statement name agrees with the convention for Javadoc links, that
+ * is: the concatenation of the fully qualified name of the type, with
+ * the string {@code #}, the name of the annotated member, and the raw
+ * types of the method parameters, enclosed in parentheses and separated
+ * by commas, for example, {@code "org.example.Library#emptyTrash()"}.
+ *
+ *
A method must not be annotated with more than one of
+ * {@code JakartaQuery}, {@code JakartaStatement}, {@code NatveQuery},
+ * {@code NativeStatement}, and {@code jakarta.data.repository.Query}.
+ *
+ * @see NativeQuery
+ * @see StatementOptions
+ *
+ * @since 4.0
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+public @interface NativeStatement {
+ /**
+ * The statement string in the native SQL dialect of the database.
+ */
+ String value();
+}
diff --git a/api/src/main/java/jakarta/persistence/query/QueryOptions.java b/api/src/main/java/jakarta/persistence/query/QueryOptions.java
index 403345605..195127444 100644
--- a/api/src/main/java/jakarta/persistence/query/QueryOptions.java
+++ b/api/src/main/java/jakarta/persistence/query/QueryOptions.java
@@ -35,20 +35,22 @@
*
Configures options that affect the execution of a query.
* This annotation may be applied to:
*
- *
a method with a {@link JakartaQuery} or Jakarta Data
- * {@code jakarta.data.repository.Query} annotation,
- *
a method with a {@link NativeQuery} annotation,
- *
a Jakarta Data repository method annotated
- * {@code jakarta.data.repository.Delete} that uses the
- * parameter-based automatic query pattern,
- * or
+ *
a method with a {@link JakartaQuery} annotation,
+ *
a method with a Jakarta Data
+ * {@code jakarta.data.repository.Query} annotation
+ * specifying a {@code SELECT} query,
+ *
a method with a {@link NativeQuery} annotation, or
*
a Jakarta Data repository method annotated
* {@code jakarta.data.repository.Find}.
*
+ *
This annotation must not be applied to a method annotated
+ * {@link JakartaStatement} or {@link NativeStatement}.
*
*
This annotation must be respected by an implementation
* of Jakarta Data backed by Jakarta Persistence.
*
+ * @see StatementOptions
+ *
* @since 4.0
*/
@Target(METHOD)
@@ -58,9 +60,6 @@
* The {@linkplain CacheStoreMode cache store mode} to use.
* The presence of this annotation overrides the default
* cache store mode of the persistence context.
- *
- * This option applies when the query is a JPQL {@code select}
- * query or a native query that returns a result set.
*
* @see jakarta.persistence.TypedQuery#setCacheStoreMode
*/
@@ -70,9 +69,6 @@
* The {@linkplain CacheRetrieveMode cache retrieve mode}
* to use. The presence of this annotation overrides the
* default cache retrieve mode of the persistence context.
- *
- * This option applies when the query is a JPQL {@code select}
- * query or a native query that returns a result set.
*
* @see jakarta.persistence.TypedQuery#setCacheRetrieveMode
*/
@@ -101,9 +97,6 @@
*
If a lock mode is explicitly specified for a
* {@linkplain NativeQuery native query}, the behavior
* is undefined and unportable between persistence providers.
- *
- * This option applies when the query is a JPQL {@code select}
- * query or a native query that returns a result set.
*
* @see jakarta.persistence.TypedQuery#setLockMode
*/
@@ -112,9 +105,6 @@
/**
* The pessimistic lock scope to use in query execution if a
* pessimistic lock mode is specified via {@link #lockMode}.
- *
- * This option applies when the query is a JPQL {@code select}
- * query or a native query that returns a result set.
*/
PessimisticLockScope lockScope() default PessimisticLockScope.NORMAL;
@@ -142,4 +132,4 @@
* @see Query#setQueryFlushMode(QueryFlushMode)
*/
QueryFlushMode flush() default QueryFlushMode.DEFAULT;
-}
\ No newline at end of file
+}
diff --git a/api/src/main/java/jakarta/persistence/query/StatementOptions.java b/api/src/main/java/jakarta/persistence/query/StatementOptions.java
new file mode 100644
index 000000000..42ca4d29b
--- /dev/null
+++ b/api/src/main/java/jakarta/persistence/query/StatementOptions.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2026 Contributors to the Eclipse Foundation
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0,
+ * or the Eclipse Distribution License v. 1.0 which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
+ */
+
+// Contributors:
+// Gavin King - 4.0
+
+package jakarta.persistence.query;
+
+import jakarta.persistence.QueryFlushMode;
+import jakarta.persistence.QueryHint;
+import jakarta.persistence.Statement;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Configures options that affect the execution of a statement.
+ * This annotation may be applied to:
+ *
+ *
a method with a {@link JakartaStatement} annotation,
+ *
a method with a {@link NativeStatement} annotation,
+ *
a method with a Jakarta Data {@code jakarta.data.repository.Query}
+ * annotation specifying an {@code UPDATE} or {@code DELETE} statement,
+ * or
+ *
a Jakarta Data repository method annotated
+ * {@code jakarta.data.repository.Delete} that uses the
+ * parameter-based automatic query pattern.
+ *
+ *
This annotation must not be applied to a method annotated
+ * {@link JakartaQuery} or {@link NativeQuery}.
+ *
+ *
This annotation must be respected by an implementation
+ * of Jakarta Data backed by Jakarta Persistence.
+ *
+ * @see QueryOptions
+ *
+ * @since 4.0
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+public @interface StatementOptions {
+ /**
+ * A statement timeout in milliseconds.
+ * By default, there is no timeout.
+ * @see Statement#setTimeout
+ */
+ int timeout() default -1;
+
+ /**
+ * Statement properties and hints.
+ * May include vendor-specific hints.
+ * @see Statement#setHint(String, Object)
+ */
+ QueryHint[] hints() default {};
+
+ /**
+ * The {@linkplain QueryFlushMode query flush mode} to use when
+ * executing the statement.
+ * @see Statement#setQueryFlushMode(QueryFlushMode)
+ */
+ QueryFlushMode flush() default QueryFlushMode.DEFAULT;
+}
diff --git a/api/src/main/java/jakarta/persistence/query/StaticStatementReference.java b/api/src/main/java/jakarta/persistence/query/StaticStatementReference.java
index fc5e375bd..e822c9410 100644
--- a/api/src/main/java/jakarta/persistence/query/StaticStatementReference.java
+++ b/api/src/main/java/jakarta/persistence/query/StaticStatementReference.java
@@ -24,8 +24,8 @@
import static java.util.Collections.emptyMap;
/**
- * A reference to a statement declared using a {@link JakartaQuery}
- * or {@link NativeQuery} annotation. An instance of this
+ * A reference to a statement declared using a {@link JakartaStatement}
+ * or {@link NativeStatement} annotation. An instance of this
* class is usually instantiated by a generated method of the
* {@linkplain jakarta.persistence.metamodel.StaticMetamodel
* static metamodel} for the annotated program element.
@@ -47,12 +47,16 @@ public class StaticStatementReference
/**
* Intended for use in code generated by an annotation processor.
* This constructor overload is adapted to the case where the
- * program element is annotated with {@link QueryOptions}.
+ * program element is annotated with {@link StatementOptions}.
*
- * @param queryName The name of the query, the concatenation of
- * the unqualified name of the annotated type,
- * with the string {@code "."}, and the name of
- * the annotated member
+ * @param statementName
+ * The name of the statement, following the convention
+ * for Javadoc links: the concatenation of the fully
+ * qualified name of the type declaring the annotated
+ * method, {@code "#"}, the method name, and the raw
+ * parameter types (with fully qualified names for
+ * reference types), enclosed in parentheses and
+ * separated by commas
* @param annotatedClass The annotated class
* @param annotatedMemberName The name of the annotated member
* @param parameterTypes The types of the parameters of the
@@ -61,11 +65,11 @@ public class StaticStatementReference
* annotated member
* @param arguments The arguments supplied to the parameters
* at runtime
- * @param hints See {@link QueryOptions#hints}
+ * @param hints See {@link StatementOptions#hints}
* @param options All specified {@linkplain Statement.Option options}
*/
public StaticStatementReference(
- @Nonnull String queryName,
+ @Nonnull String statementName,
@Nonnull Class> annotatedClass,
@Nonnull String annotatedMemberName,
@Nonnull List> parameterTypes,
@@ -73,7 +77,7 @@ public StaticStatementReference(
@Nonnull List